Merge pull request #1093 from hashicorp/nd/codeowners #924
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright (c) HashiCorp, Inc. | |
name: build | |
on: | |
push: | |
# Sequence of patterns matched against refs/heads | |
branches: | |
# Push events on main branch | |
- main | |
# Push events to branches matching refs/heads/release/** | |
- "release/**" | |
env: | |
PKG_NAME: "consul-terraform-sync" | |
GO_TAGS: "" | |
CGO_ENABLED: 0 | |
jobs: | |
get-product-version: | |
runs-on: ubuntu-latest | |
outputs: | |
product-version: ${{ steps.get-product-version.outputs.product-version }} | |
steps: | |
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 | |
- name: get product version | |
id: get-product-version | |
run: | | |
make version | |
echo "::set-output name=product-version::$(make version)" | |
generate-metadata-file: | |
needs: get-product-version | |
runs-on: ubuntu-latest | |
outputs: | |
filepath: ${{ steps.generate-metadata-file.outputs.filepath }} | |
steps: | |
- name: "Checkout directory" | |
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 | |
- name: Generate metadata file | |
id: generate-metadata-file | |
uses: hashicorp/actions-generate-metadata@v1 | |
with: | |
version: ${{ needs.get-product-version.outputs.product-version }} | |
product: ${{ env.PKG_NAME }} | |
- uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3 | |
with: | |
name: metadata.json | |
path: ${{ steps.generate-metadata-file.outputs.filepath }} | |
set-ld-flags: | |
needs: get-product-version | |
runs-on: ubuntu-latest | |
outputs: | |
ldflags: ${{ steps.generate-ld-flags.outputs.ldflags }} | |
steps: | |
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 | |
- name: "Generate ld flags" | |
id: generate-ld-flags | |
run: | | |
project="$(go list -m)" | |
sha="$(git rev-parse --short HEAD)" | |
echo "::set-output name=ldflags::"-s -w -X \'$project/version.Name=${{ env.PKG_NAME }}\' \ | |
-X \'$project/version.GitCommit=$sha\' \ | |
-X \'$project/version.GitDescribe=v$(make version base=1)\'"" | |
build: | |
needs: [get-product-version, set-ld-flags] | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
include: | |
- { go: "1.22.4", goos: "linux", goarch: "386" } | |
- { go: "1.22.4", goos: "linux", goarch: "amd64" } | |
- { go: "1.22.4", goos: "linux", goarch: "arm" } | |
- { go: "1.22.4", goos: "linux", goarch: "arm64" } | |
- { go: "1.22.4", goos: "freebsd", goarch: "386" } | |
- { go: "1.22.4", goos: "freebsd", goarch: "amd64" } | |
- { go: "1.22.4", goos: "windows", goarch: "386" } | |
- { go: "1.22.4", goos: "windows", goarch: "amd64" } | |
- { go: "1.22.4", goos: "solaris", goarch: "amd64" } | |
- { go: "1.22.4", goos: "darwin", goarch: "amd64" } | |
- { go: "1.22.4", goos: "darwin", goarch: "arm64" } | |
fail-fast: true | |
name: Go ${{ matrix.go }} ${{ matrix.goos }} ${{ matrix.goarch }} build | |
steps: | |
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 | |
- name: Setup go | |
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1 | |
with: | |
go-version: ${{ matrix.go }} | |
- name: Build | |
env: | |
GOOS: ${{ matrix.goos }} | |
GOARCH: ${{ matrix.goarch }} | |
LD_FLAGS: ${{ needs.set-ld-flags.outputs.ldflags }} | |
run: | | |
mkdir dist out | |
cp LICENSE dist/LICENSE.txt | |
go build -o dist/ \ | |
-ldflags "${{ env.LD_FLAGS }}" \ | |
-tags "${{ env.GO_TAGS }}" | |
zip -r -j out/${{ env.PKG_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip dist/ | |
- uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3 | |
with: | |
name: ${{ env.PKG_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip | |
path: out/${{ env.PKG_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip | |
- name: Copy license file | |
if: ${{ matrix.goos == 'linux' }} | |
env: | |
LICENSE_DIR: ".release/linux/package/usr/share/doc/${{ env.PKG_NAME }}" | |
run: | | |
mkdir -p "$LICENSE_DIR" | |
cp LICENSE "$LICENSE_DIR/LICENSE.txt" | |
- name: Package | |
if: ${{ matrix.goos == 'linux' }} | |
uses: hashicorp/actions-packaging-linux@v1 | |
with: | |
name: ${{ github.event.repository.name }} | |
description: "Consul-Terraform-Sync is a service-oriented tool for managing network infrastructure near real-time." | |
arch: ${{ matrix.goarch }} | |
version: ${{ needs.get-product-version.outputs.product-version }} | |
maintainer: "HashiCorp" | |
homepage: "https://github.com/hashicorp/consul-terraform-sync" | |
license: "MPL-2.0" | |
binary: "dist/${{ env.PKG_NAME }}" | |
deb_depends: "openssl" | |
rpm_depends: "openssl" | |
config_dir: ".release/linux/package" | |
- name: Set Package Names | |
if: ${{ matrix.goos == 'linux' }} | |
run: | | |
echo "RPM_PACKAGE=$(basename out/*.rpm)" >> $GITHUB_ENV | |
echo "DEB_PACKAGE=$(basename out/*.deb)" >> $GITHUB_ENV | |
- uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3 | |
if: ${{ matrix.goos == 'linux' }} | |
with: | |
name: ${{ env.RPM_PACKAGE }} | |
path: out/${{ env.RPM_PACKAGE }} | |
- uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3 | |
if: ${{ matrix.goos == 'linux' }} | |
with: | |
name: ${{ env.DEB_PACKAGE }} | |
path: out/${{ env.DEB_PACKAGE }} | |
build-docker: | |
name: Docker ${{ matrix.arch }} build | |
needs: | |
- get-product-version | |
- build | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
arch: ["arm", "arm64", "386", "amd64"] | |
env: | |
repo: ${{github.event.repository.name}} | |
version: ${{needs.get-product-version.outputs.product-version}} | |
steps: | |
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 | |
- name: Docker Build (Action) | |
uses: hashicorp/actions-docker-build@v2 | |
with: | |
version: ${{env.version}} | |
target: default | |
arch: ${{matrix.arch}} | |
tags: | | |
docker.io/hashicorp/${{env.repo}}:${{env.version}} |