Skip to content

update release to use public common repo #13

update release to use public common repo

update release to use public common repo #13

Workflow file for this run

name: Release
on:
push:
branches:
- main
paths:
- src/manifest.json
- .gitmodules
- .github/workflows/release.yml
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
detect-version:
name: Identify Release Version
runs-on: ubuntu-slim
permissions:
contents: read
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
outputs:
should_release: ${{ steps.detect.outputs.should_release }}
version: ${{ steps.detect.outputs.version }}
tag: ${{ steps.detect.outputs.tag }}
steps:
- name: Checkout Code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Detect Manifest Version
id: detect
shell: bash
run: |
set -euo pipefail
version="$(python3 -c 'import json; print(json.load(open("src/manifest.json", "r", encoding="utf-8")).get("version", ""))')"
if [[ -z "$version" ]]; then
echo "::error::Unable to read src/manifest.json version"
exit 1
fi
tag="$version"
if [[ "$tag" == v* ]]; then
tag="$tag"
elif [[ "$tag" == V* ]]; then
tag="v${tag:1}"
else
tag="v$tag"
fi
legacy_tag="$version"
should_release="true"
if gh api "/repos/${GITHUB_REPOSITORY}/git/ref/tags/${tag}" --silent >/dev/null 2>&1; then
should_release="false"
fi
if [[ "$legacy_tag" != "$tag" ]]; then
if gh api "/repos/${GITHUB_REPOSITORY}/git/ref/tags/${legacy_tag}" --silent >/dev/null 2>&1; then
should_release="false"
fi
fi
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "tag=$tag" >> "$GITHUB_OUTPUT"
echo "should_release=$should_release" >> "$GITHUB_OUTPUT"
if [[ "$should_release" == "false" ]]; then
echo "No release needed. Manifest version '$version' already has a matching tag."
else
echo "Release needed for manifest version '$version'."
fi
create-release:
name: Create Tag + Release
needs: detect-version
if: ${{ needs.detect-version.outputs.should_release == 'true' }}
runs-on: ubuntu-slim
permissions:
contents: write
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
VERSION: ${{ needs.detect-version.outputs.version }}
TAG: ${{ needs.detect-version.outputs.tag }}
outputs:
tag: ${{ steps.meta.outputs.tag }}
steps:
- name: Publish Metadata
id: meta
shell: bash
run: |
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
- name: Create Tag
shell: bash
run: |
gh api -X POST "/repos/${GITHUB_REPOSITORY}/git/refs" -f ref="refs/tags/${TAG}" -f sha="${GITHUB_SHA}"
- name: Create Release
shell: bash
run: |
gh release create "${TAG}" --repo "${GH_REPO}" --title "${TAG}" --notes "Automated release for version ${VERSION}"
build-assets:
name: Build And Upload (${{ matrix.arch }})
needs:
- detect-version
- create-release
if: ${{ needs.detect-version.outputs.should_release == 'true' }}
runs-on: ${{ matrix.runner }}
permissions:
contents: write
strategy:
fail-fast: false
matrix:
include:
- arch: amd64
runner: windows-latest
- arch: arm64
runner: windows-11-arm
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GOBIN: ${{ github.workspace }}\go-bin
QGO_VERSION: 1.2.8
VERSION: ${{ needs.detect-version.outputs.version }}
TAG: ${{ needs.detect-version.outputs.tag }}
steps:
- name: Checkout Code
uses: actions/checkout@v6
with:
fetch-depth: 0
submodules: recursive
- name: Link Common Modules To Expected Path
shell: pwsh
run: |
if (!(Test-Path ".\common")) {
Write-Error "Expected submodule '.\\common' was not checked out. Ensure the repository includes the common submodule."
exit 1
}
$commonTarget = (Resolve-Path ".\common").Path
if (Test-Path "..\common") {
Remove-Item "..\common" -Recurse -Force
}
New-Item -ItemType Junction -Path "..\common" -Target $commonTarget | Out-Null
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: src/go.mod
cache-dependency-path: src/go.sum
- name: Cache qgo binary
uses: actions/cache@v4
with:
path: ${{ env.GOBIN }}
key: qgo-${{ runner.os }}-${{ runner.arch }}-${{ env.QGO_VERSION }}
- name: Install qgo if not cached
shell: pwsh
run: |
if (!(Test-Path "$env:GOBIN\qgo.exe")) {
go install github.com/quikdev/go/cmd/qgo@v${{ env.QGO_VERSION }}
} else {
Write-Host "using cached qgo binary"
}
- name: Add qgo to PATH
shell: pwsh
run: |
echo "${env:GOBIN}" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
- name: Build Binary + Package Asset
shell: pwsh
working-directory: src
run: |
New-Item -ItemType Directory -Force -Path "..\artifacts" | Out-Null
$env:GOOS = "windows"
$env:GOARCH = "${{ matrix.arch }}"
qgo build --no-cache
$assetDir = "..\artifacts\${{ matrix.arch }}"
New-Item -ItemType Directory -Force -Path $assetDir | Out-Null
Copy-Item "..\..\bin\nvm.exe" "$assetDir\nvm.exe" -Force
$hash = (Get-FileHash "$assetDir\nvm.exe" -Algorithm SHA256).Hash.ToLower()
"$hash *nvm.exe" | Out-File -FilePath "$assetDir\SHASUM.txt" -Encoding ascii -NoNewline
Compress-Archive -Path "$assetDir\nvm.exe", "$assetDir\SHASUM.txt" -DestinationPath "..\artifacts\nvm-${{ matrix.arch }}.zip" -Force
- name: Upload Release Assets
shell: pwsh
run: |
gh release upload "$env:TAG" "artifacts\nvm-${{ matrix.arch }}.zip" --clobber
rollback:
name: Rollback Failed Release
needs:
- detect-version
- create-release
- build-assets
if: ${{ failure() && needs.detect-version.outputs.should_release == 'true' }}
runs-on: ubuntu-slim
permissions:
contents: write
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ needs.detect-version.outputs.tag }}
steps:
- name: Remove Release Then Tag
shell: bash
run: |
set -euo pipefail
release_id=""
if release_id=$(gh api "/repos/${GITHUB_REPOSITORY}/releases/tags/${TAG}" --jq '.id' 2>/dev/null); then
if [[ -n "${release_id}" && "${release_id}" != "null" ]]; then
gh api -X DELETE "/repos/${GITHUB_REPOSITORY}/releases/${release_id}"
fi
fi
gh api -X DELETE "/repos/${GITHUB_REPOSITORY}/git/refs/tags/${TAG}" || true
no-op:
name: No Release Needed
needs: detect-version
if: ${{ needs.detect-version.outputs.should_release != 'true' }}
runs-on: ubuntu-slim
steps:
- name: Skip
run: |
echo "Manifest version '${{ needs.detect-version.outputs.version }}' already has a matching tag."