-
Notifications
You must be signed in to change notification settings - Fork 177
188 lines (175 loc) · 7.98 KB
/
build.yml
File metadata and controls
188 lines (175 loc) · 7.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# This workflow builds the product for all supported platforms and uploads the resulting
# binaries as Actions artifacts. The workflow also uploads a build metadata file
# (metadata.json) -- and a Terraform Registry manifest file (terraform-registry-manifest.json).
name: build
# We default to running this workflow on every push to every branch.
# This provides fast feedback when build issues occur, so they can be
# fixed prior to being merged to the main branch.
#
# If you want to opt out of this, and only run the build on certain branches
# please refer to the documentation on branch filtering here:
#
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#onpushbranchestagsbranches-ignoretags-ignore
#
on: [workflow_dispatch, push]
env:
PKG_NAME: "terraform-provider-tfe"
jobs:
# Detects the Go toolchain version to use for product builds.
#
# The implementation is inspired by envconsul -- https://go.hashi.co/get-go-version-example
get-go-version:
name: "Detect Go toolchain version"
runs-on: ubuntu-latest
outputs:
go-version: ${{ steps.get-go-version.outputs.go-version }}
steps:
- uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
- uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
with:
go-version-file: 'go.mod'
- name: Detect Go version
id: get-go-version
run: |
version="$(go list -f {{.GoVersion}} -m)"
echo "go-version=$version" >> "$GITHUB_OUTPUT"
# Parses the version/VERSION file.
#
# Reference: https://github.com/hashicorp/actions-set-product-version/blob/main/README.md
set-product-version:
name: "Parse version file"
runs-on: ubuntu-latest
outputs:
product-version: ${{ steps.set-product-version.outputs.product-version }}
product-base-version: ${{ steps.set-product-version.outputs.base-product-version }}
product-prerelease-version: ${{ steps.set-product-version.outputs.prerelease-product-version }}
product-minor-version: ${{ steps.set-product-version.outputs.minor-product-version }}
steps:
- uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
- name: Set variables
id: set-product-version
uses: hashicorp/actions-set-product-version@2ec1b51402b3070bccf7ca95306afbd039e574ff # v2.0.1
# Creates metadata.json file containing build metadata for consumption by CRT workflows.
#
# Reference: https://github.com/hashicorp/actions-generate-metadata/blob/main/README.md
generate-metadata-file:
needs: set-product-version
runs-on: ubuntu-latest
outputs:
filepath: ${{ steps.generate-metadata-file.outputs.filepath }}
steps:
- name: "Checkout directory"
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
- name: Generate metadata file
id: generate-metadata-file
uses: hashicorp/actions-generate-metadata@v1
with:
version: ${{ needs.set-product-version.outputs.product-version }}
product: ${{ env.PKG_NAME }}
repositoryOwner: "hashicorp"
- uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: metadata.json
path: ${{ steps.generate-metadata-file.outputs.filepath }}
# Uploads an Actions artifact named terraform-registry-manifest.json.zip.
#
# The artifact contains a single file with a filename that Terraform Registry expects
# (example: terraform-provider-crt-example_2.3.6-alpha1_manifest.json). The file contents
# are identical to the terraform-registry-manifest.json file in the source repository.
upload-terraform-registry-manifest-artifact:
needs: set-product-version
runs-on: ubuntu-latest
steps:
- name: "Checkout directory"
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
with:
path: ${{ env.PKG_NAME }}
- name: "Copy manifest from checkout directory to a file with the desired name"
id: terraform-registry-manifest
run: |
name="${{ env.PKG_NAME }}"
version="${{ needs.set-product-version.outputs.product-version }}"
source="${name}/terraform-registry-manifest.json"
destination="${name}_${version}_manifest.json"
cp "$source" "$destination"
echo "filename=$destination" >> "$GITHUB_OUTPUT"
- uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: terraform-registry-manifest.json
path: ${{ steps.terraform-registry-manifest.outputs.filename }}
if-no-files-found: error
# Builds the product for all platforms except macOS.
#
# With `reproducible: report`, this job also reports whether the build is reproducible,
# but does not enforce it.
#
# Reference: https://github.com/hashicorp/actions-go-build/blob/main/README.md
build:
needs:
- get-go-version
- set-product-version
runs-on: ubuntu-latest
strategy:
fail-fast: true
# TODO: Customize `matrix` for your provider. Compare to existing .goreleaser.yml.
# Verify expected Artifacts list for a workflow run.
matrix:
goos: [freebsd, windows, linux, darwin]
goarch: ["386", "amd64", "arm", "arm64"]
exclude:
- goos: freebsd
goarch: arm64
- goos: windows
goarch: arm64
- goos: windows
goarch: arm
- goos: darwin
goarch: 386
- goos: darwin
goarch: arm
name: Go ${{ needs.get-go-version.outputs.go-version }} ${{ matrix.goos }} ${{ matrix.goarch }} build
steps:
- uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
- uses: hashicorp/actions-go-build@v1
env:
CGO_ENABLED: 0
BASE_VERSION: ${{ needs.set-product-version.outputs.product-base-version }}
PRERELEASE_VERSION: ${{ needs.set-product-version.outputs.product-prerelease-version}}
METADATA_VERSION: ${{ env.METADATA }}
with:
# TODO: Customize `bin_name` for your provider. Compare to existing .goreleaser.yml.
# Protocol v6 providers should omit the `_x5` suffix.
bin_name: "${{ env.PKG_NAME }}_v${{ needs.set-product-version.outputs.product-version }}_x5"
product_name: ${{ env.PKG_NAME }}
product_version: ${{ needs.set-product-version.outputs.product-version }}
go_version: ${{ needs.get-go-version.outputs.go-version }}
os: ${{ matrix.goos }}
arch: ${{ matrix.goarch }}
reproducible: report
# TODO: Customize `go build` flags for your provider. Compare to existing .goreleaser.yml.
# TODO: Customize `ldflags` for your provider. Ensure that the import path and name in the -X flag
# are correct for your provider.
instructions: |
go build \
-o "$BIN_PATH" \
-trimpath \
-buildvcs=false \
-ldflags "-s -w -X 'version.ProviderVersion=${{ needs.set-product-version.outputs.product-version }}'"
cp LICENSE "$TARGET_DIR/LICENSE.txt"
whats-next:
needs:
- build
- generate-metadata-file
- upload-terraform-registry-manifest-artifact
runs-on: ubuntu-latest
name: "What's next?"
steps:
- name: "Write a helpful summary"
run: |
github_dot_com="${{ github.server_url }}"
owner_with_name="${{ github.repository }}"
ref="${{ github.ref }}"
echo "### What's next?" >> "$GITHUB_STEP_SUMMARY"
echo "#### For a release branch (see \`.release/ci.hcl\`)" >> $GITHUB_STEP_SUMMARY
echo "After this \`build\` workflow run completes succesfully, you can expect the CRT \`prepare\` workflow to begin momentarily." >> "$GITHUB_STEP_SUMMARY"
echo "To find the \`prepare\` workflow run, [view the checks for this commit]($github_dot_com/$owner_with_name/commits/$ref)" >> "$GITHUB_STEP_SUMMARY"