Skip to content

Build & Release

Build & Release #1833

Workflow file for this run

name: Build & Release
on:
push:
tags:
- v**
workflow_run:
workflows: ["Automatically release a new version of flyctl"]
types:
- completed
workflow_dispatch:
# need this until this file is on the default branch so tag creates are picked up
workflow_call:
permissions:
contents: write
# concurrency:
# group: ${{ github.workflow }}-${{ github.ref }}
# cancel-in-progress: true
jobs:
debug:
runs-on: ubuntu-latest
steps:
- run: echo "$GITHUB_CONTEXT"
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
meta:
runs-on: ubuntu-latest
outputs:
sha_short: ${{ steps.gen.outputs.sha_short }}
json: ${{ steps.gen.outputs.json }}
version: ${{ fromJSON(steps.gen.outputs.json).version }}
tag: ${{ fromJSON(steps.gen.outputs.json).tag }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
- name: Generate release meta
run: |
go run ./tools/version show > release.json
- name: Output release meta
id: gen
run: |
cat release.json | jq
echo "sha_short=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
echo "json=$(cat release.json)" >> "$GITHUB_OUTPUT"
- uses: actions/upload-artifact@v4
with:
name: build-artifacts
path: |
release.json
overwrite: true
build:
needs: meta
strategy:
matrix:
GOOS: [linux, windows, darwin]
runs-on: ubuntu-latest-m
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
- name: Place wintun.dll
run: cp -r deps/wintun/bin/amd64/wintun.dll ./
- id: cache
uses: actions/cache@v4
with:
path: dist/${{ matrix.GOOS }}
key: ${{ matrix.GOOS }}-${{ needs.meta.outputs.sha_short }}
- name: Run GoReleaser
if: steps.cache.outputs.cache-hit != 'true' # do not run if cache hit
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser-pro
version: latest
args: release --clean -f .goreleaser.2.yml --fail-fast --split
env:
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GGOOS: ${{ matrix.GOOS }}
release:
runs-on: ubuntu-latest
needs: [meta, build]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
# copy the caches from prepare
- uses: actions/cache@v4
with:
path: dist/linux
key: linux-${{ needs.meta.outputs.sha_short }}
- uses: actions/cache@v4
with:
path: dist/darwin
key: darwin-${{ needs.meta.outputs.sha_short }}
- uses: actions/cache@v4
with:
path: dist/windows
key: windows-${{ needs.meta.outputs.sha_short }}
- name: Write release meta
env:
RELEASE_JSON: ${{ needs.meta.outputs.json }}
run: echo "$RELEASE_JSON" > ./dist/release.json
- uses: actions/upload-artifact@v4
with:
name: build-artifacts
path: |
dist/**/*.json
dist/**/*.zip
dist/**/*.tar.gz
retention-days: 1
overwrite: true
- name: Github release
if: steps.cache.outputs.cache-hit != 'true' && github.ref == 'refs/heads/master'
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser-pro
version: latest
args: continue --merge
env:
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GGOOS: ${{ matrix.GOOS }}
sync_docs:
needs: release
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v0.') && !contains(github.ref, 'pre') && !contains(github.ref, 'dev-')
steps:
- name: Checkout flyctl
uses: actions/checkout@v4
- uses: jnwng/github-app-installation-token-action@778da2ab509f3ef5e4b902bc15daf25ef3e34939
id: installationToken
with:
appId: 339363
installationId: 37947271
privateKey: ${{ secrets.DOCS_SYNCER_GITHUB_APP_PRIVATE_KEY }}
- name: Checkout docs
uses: actions/checkout@v4
with:
repository: superfly/docs
token: ${{ steps.installationToken.outputs.token }}
path: docs
- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
check-latest: true
- name: Publish CLI docs
id: publish-cli-docs
env:
GITHUB_TOKEN: ${{ steps.installationToken.outputs.token }}
run: scripts/publish_docs.sh ${{ github.ref_name }}