| --- | |
| name: build_terraform | |
| # This workflow is intended to be called by the build workflow. The crt make | |
| # targets that are utilized automatically determine build metadata and | |
| # handle building and packing Terraform. | |
| on: | |
| workflow_call: | |
| inputs: | |
| cgo-enabled: | |
| type: string | |
| required: true | |
| goos: | |
| required: true | |
| type: string | |
| goarch: | |
| required: true | |
| type: string | |
| go-version: | |
| type: string | |
| package-name: | |
| type: string | |
| default: terraform | |
| product-version: | |
| type: string | |
| required: true | |
| ld-flags: | |
| type: string | |
| required: true | |
| runson: | |
| type: string | |
| required: true | |
| permissions: | |
| contents: read | |
| statuses: write | |
| jobs: | |
| build: | |
| runs-on: ${{ inputs.runson }} | |
| name: Terraform ${{ inputs.goos }} ${{ inputs.goarch }} v${{ inputs.product-version }} | |
| steps: | |
| - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 | |
| - uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6.5.0 | |
| with: | |
| go-version: ${{ inputs.go-version }} | |
| - name: Build Terraform | |
| env: | |
| GOOS: ${{ inputs.goos }} | |
| GOARCH: ${{ inputs.goarch }} | |
| GO_LDFLAGS: ${{ inputs.ld-flags }} | |
| ACTIONSOS: ${{ inputs.runson }} | |
| CGO_ENABLED: ${{ inputs.cgo-enabled }} | |
| uses: hashicorp/actions-go-build@dd7ca5a30c402c933e1fe61e0ff7165e5c4ee9e4 # v1.1.2 | |
| with: | |
| product_name: ${{ inputs.package-name }} | |
| product_version: ${{ inputs.product-version }} | |
| go_version: ${{ inputs.go-version }} | |
| os: ${{ inputs.goos }} | |
| arch: ${{ inputs.goarch }} | |
| reproducible: nope | |
| instructions: |- | |
| go build -ldflags "${{ inputs.ld-flags }}" -o "$BIN_PATH" -trimpath -buildvcs=false | |
| cp LICENSE "$TARGET_DIR/LICENSE.txt" | |
| - name: Copy license file to config_dir | |
| if: ${{ inputs.goos == 'linux' }} | |
| env: | |
| LICENSE_DIR: ".release/linux/package/usr/share/doc/${{ inputs.package-name }}" | |
| run: | | |
| mkdir -p "$LICENSE_DIR" && cp LICENSE "$LICENSE_DIR/LICENSE.txt" | |
| - if: ${{ inputs.goos == 'linux' }} | |
| uses: hashicorp/actions-packaging-linux@006298649be64cee63e7f94a54dfcf3e14766bf6 # v1.11 | |
| with: | |
| name: "terraform" | |
| description: "Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned." | |
| arch: ${{ inputs.goarch }} | |
| version: ${{ inputs.product-version }} | |
| maintainer: "HashiCorp" | |
| homepage: "https://terraform.io/" | |
| license: "BUSL-1.1" | |
| binary: "dist/terraform" | |
| deb_depends: "git" | |
| rpm_depends: "git" | |
| config_dir: ".release/linux/package/" | |
| - if: ${{ inputs.goos == 'linux' }} | |
| name: Determine package file names | |
| run: | | |
| echo "RPM_PACKAGE=$(basename out/*.rpm)" >> $GITHUB_ENV | |
| echo "DEB_PACKAGE=$(basename out/*.deb)" >> $GITHUB_ENV | |
| - if: ${{ inputs.goos == 'linux' }} | |
| uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 | |
| with: | |
| name: ${{ env.RPM_PACKAGE }} | |
| path: out/${{ env.RPM_PACKAGE }} | |
| if-no-files-found: error | |
| - if: ${{ inputs.goos == 'linux' }} | |
| uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 | |
| with: | |
| name: ${{ env.DEB_PACKAGE }} | |
| path: out/${{ env.DEB_PACKAGE }} | |
| if-no-files-found: error |