-
Notifications
You must be signed in to change notification settings - Fork 2
Feat #1185: publish prebuilt terraform-provider packages #406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ThomBogers
wants to merge
3
commits into
master
Choose a base branch
from
feat/terraform-provider-release
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+180
−5
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
93e62a1
feat: publish prebuilt terraform-provider packages on every push to m…
ThomBogers 0770f89
fix(terraform-provider): keep the dev build as the only 0.1.0 in the …
ThomBogers ea17312
fix(terraform-provider): swap the rolling release atomically, address…
ThomBogers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| name: Release terraform-provider | ||
|
|
||
| on: | ||
| push: | ||
| branches: [master] | ||
|
|
||
| permissions: {} | ||
|
|
||
| concurrency: | ||
| group: release-terraform-provider | ||
| cancel-in-progress: false | ||
|
|
||
| env: | ||
| # The version OpenTofu/Terraform select on. It is part of the package | ||
| # filename, so it must be a plain semver; the rolling build id goes into the | ||
| # binary instead. Keep in sync with the plugin dir in terraform-provider/mod.just. | ||
| PROVIDER_VERSION: "0.1.0" | ||
|
|
||
| jobs: | ||
| release: | ||
| runs-on: ubuntu-24.04 | ||
| permissions: | ||
| contents: write | ||
| steps: | ||
| - uses: actions/checkout@v5 | ||
|
|
||
| - name: Setup Go | ||
| uses: actions/setup-go@v5 | ||
| with: | ||
| go-version-file: go.mod | ||
|
|
||
| - name: Build provider packages | ||
| run: | | ||
| VERSION="${GITHUB_SHA::7}-master-${{ github.run_number }}" | ||
| echo "VERSION=${VERSION}" >> "$GITHUB_ENV" | ||
|
|
||
| # Packages follow the provider registry layout so that a zip dropped | ||
| # unchanged into a local plugin mirror is picked up by `tofu init`: | ||
| # terraform-provider-fundament_<semver>_<os>_<arch>.zip | ||
| # containing a single terraform-provider-fundament_v<semver>[.exe]. | ||
| mkdir -p dist | ||
| for target in linux/amd64 linux/arm64 darwin/arm64 windows/amd64; do | ||
| GOOS="${target%/*}" | ||
| GOARCH="${target#*/}" | ||
| OUT_DIR="dist/terraform-provider-fundament_${GOOS}_${GOARCH}" | ||
| BIN="terraform-provider-fundament_v${PROVIDER_VERSION}" | ||
| if [ "$GOOS" = "windows" ]; then | ||
| BIN="${BIN}.exe" | ||
| fi | ||
| mkdir -p "$OUT_DIR" | ||
| CGO_ENABLED=0 GOOS="$GOOS" GOARCH="$GOARCH" \ | ||
| go build -trimpath \ | ||
| -ldflags "-s -w -X main.version=${VERSION}" \ | ||
| -o "$OUT_DIR/$BIN" ./terraform-provider | ||
| (cd "$OUT_DIR" && zip -q "../terraform-provider-fundament_${PROVIDER_VERSION}_${GOOS}_${GOARCH}.zip" "$BIN") | ||
| done | ||
| (cd dist && sha256sum *.zip > "terraform-provider-fundament_${PROVIDER_VERSION}_SHA256SUMS") | ||
|
|
||
| - name: Update rolling release | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| run: | | ||
| # The package names are fixed, so replacing assets on the live release | ||
| # (gh release upload --clobber) would expose a mix of old and new | ||
| # packages while uploading, and a failed upload would leave it that | ||
| # way. Instead, upload everything to a draft release while the current | ||
| # one stays live, then swap: move the tag, delete the old release and | ||
| # publish the draft. The swap itself is two API calls, in which the | ||
| # download URLs 404; a downloader never sees a mix. Any failure before | ||
| # the swap leaves the current release untouched. | ||
| # | ||
| # While the draft and the published release share the tag, gh's | ||
| # tag-addressed release commands may resolve to either of them, so the | ||
| # draft is only ever addressed by id. | ||
| TAG=terraform-provider-latest | ||
| NOTES="Rolling build of the Fundament OpenTofu/Terraform provider from the latest push to master. | ||
|
|
||
| - Provider version: \`${PROVIDER_VERSION}\` | ||
| - Build: \`${VERSION}\` | ||
| - Commit: ${GITHUB_SHA} | ||
|
|
||
| See terraform-provider/README.md for install instructions." | ||
|
|
||
| OLD_ID=$(gh api "repos/${GITHUB_REPOSITORY}/releases/tags/${TAG}" --jq .id 2>/dev/null || true) | ||
|
|
||
| NEW_ID=$(gh api -X POST "repos/${GITHUB_REPOSITORY}/releases" \ | ||
| -f tag_name="$TAG" \ | ||
| -f target_commitish="$GITHUB_SHA" \ | ||
| -f name="terraform-provider (rolling)" \ | ||
| -f body="$NOTES" \ | ||
| -F draft=true \ | ||
| -F prerelease=true \ | ||
| --jq .id) | ||
| trap 'gh api -X DELETE "repos/${GITHUB_REPOSITORY}/releases/${NEW_ID}" || true' ERR | ||
|
|
||
| for f in dist/*.zip "dist/terraform-provider-fundament_${PROVIDER_VERSION}_SHA256SUMS"; do | ||
| gh api -X POST \ | ||
| -H "Content-Type: application/octet-stream" \ | ||
| "https://uploads.github.com/repos/${GITHUB_REPOSITORY}/releases/${NEW_ID}/assets?name=$(basename "$f")" \ | ||
| --input "$f" > /dev/null | ||
| done | ||
| echo "Draft release ${NEW_ID} assets:" | ||
| gh api "repos/${GITHUB_REPOSITORY}/releases/${NEW_ID}/assets" --jq '.[] | " \(.name) \(.size)"' | ||
|
|
||
| # Swap. Publishing does not move an existing tag, so move it here. | ||
| git tag -f "$TAG" | ||
| git push -f origin "$TAG" | ||
| if [ -n "$OLD_ID" ]; then | ||
| gh api -X DELETE "repos/${GITHUB_REPOSITORY}/releases/${OLD_ID}" | ||
| fi | ||
| trap - ERR | ||
| gh api -X PATCH "repos/${GITHUB_REPOSITORY}/releases/${NEW_ID}" \ | ||
| -F draft=false \ | ||
| -F prerelease=true \ | ||
| -f make_latest=false > /dev/null | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.