2023-03-28 12:39:37 -05:00
---
2023-09-21 07:27:16 -05:00
name : build_opentofu
2023-03-28 12:39:37 -05:00
# This workflow is intended to be called by the build workflow. The crt make
# targets that are utilized automatically determine build metadata and
2023-09-21 07:27:16 -05:00
# handle building and packing OpenTofu.
2023-03-28 12:39:37 -05:00
on :
workflow_call :
inputs :
cgo-enabled :
type : string
default : 0
required : true
goos :
required : true
type : string
goarch :
required : true
type : string
go-version :
type : string
package-name :
type : string
2023-09-28 03:24:30 -05:00
default : tofu
bin-name :
type : string
default : tofu
2023-03-28 12:39:37 -05:00
product-version :
type : string
required : true
ld-flags :
type : string
required : true
runson :
type : string
required : true
jobs :
build :
runs-on : ${{ inputs.runson }}
2023-09-21 07:27:16 -05:00
name : OpenTofu ${{ inputs.goos }} ${{ inputs.goarch }} v${{ inputs.product-version }}
2023-03-28 12:39:37 -05:00
steps :
2023-07-14 12:02:38 -05:00
- uses : actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- uses : actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
2023-03-28 12:39:37 -05:00
with :
go-version : ${{ inputs.go-version }}
- name : Determine artifact basename
run : echo "ARTIFACT_BASENAME=${{ inputs.package-name }}_${{ inputs.product-version }}_${{ inputs.goos }}_${{ inputs.goarch }}.zip" >> $GITHUB_ENV
2023-09-21 07:27:16 -05:00
- name : Build OpenTofu
2023-03-28 12:39:37 -05:00
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@v0.1.7
with :
2023-09-28 03:24:30 -05:00
bin_name : ${{ inputs.bin-name }}
product_name : ${{ inputs.product-name }}
2023-03-28 12:39:37 -05:00
product_version : ${{ inputs.product-version }}
go_version : ${{ inputs.go-version }}
os : ${{ inputs.goos }}
arch : ${{ inputs.goarch }}
2023-04-26 13:42:00 -05:00
reproducible : nope
2023-03-28 12:39:37 -05:00
instructions : |-
mkdir dist out
set -x
2023-09-27 07:37:55 -05:00
go build -ldflags "${{ inputs.ld-flags }}" -o dist/ ./cmd/tofu
2023-03-28 12:39:37 -05:00
zip -r -j out/${{ env.ARTIFACT_BASENAME }} dist/
2023-07-14 12:02:38 -05:00
- uses : actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
2023-03-28 12:39:37 -05:00
with :
name : ${{ env.ARTIFACT_BASENAME }}
path : out/${{ env.ARTIFACT_BASENAME }}
if-no-files-found : error
- if : ${{ inputs.goos == 'linux' }}
uses : hashicorp/actions-packaging-linux@v1
with :
2023-09-21 07:27:16 -05:00
name : "opentofu"
description : "OpenTofu enables you to safely and predictably create, change, and improve infrastructure. It is an open source tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned."
2023-03-28 12:39:37 -05:00
arch : ${{ inputs.goarch }}
version : ${{ inputs.product-version }}
maintainer : "HashiCorp"
2023-09-21 07:27:16 -05:00
homepage : "https://opentofu.org/"
2023-03-28 12:39:37 -05:00
license : "MPL-2.0"
2023-09-21 07:27:16 -05:00
binary : "dist/tofu"
2023-03-28 12:39:37 -05:00
deb_depends : "git"
rpm_depends : "git"
- 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' }}
2023-07-14 12:02:38 -05:00
uses : actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
2023-03-28 12:39:37 -05:00
with :
name : ${{ env.RPM_PACKAGE }}
path : out/${{ env.RPM_PACKAGE }}
if-no-files-found : error
- if : ${{ inputs.goos == 'linux' }}
2023-07-14 12:02:38 -05:00
uses : actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
2023-03-28 12:39:37 -05:00
with :
name : ${{ env.DEB_PACKAGE }}
path : out/${{ env.DEB_PACKAGE }}
2023-04-26 13:42:00 -05:00
if-no-files-found : error