Add upgrade test & enable init test #477
Workflow file for this run
This file contains 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
name: Build and release | |
on: | |
push: | |
branches: [trunk] | |
paths-ignore: | |
- 'docs/**' | |
- 'README.md' | |
pull_request: | |
branches: [trunk] | |
paths-ignore: | |
- 'docs/**' | |
- 'README.md' | |
jobs: | |
build: | |
name: Build | |
runs-on: ${{ matrix.os == 'windows' && 'windows-latest' || 'elvia-runner' }} | |
strategy: | |
matrix: | |
os: [linux, macos, windows] | |
arch: [amd64] | |
include: | |
- os: macos | |
arch: arm64 | |
fail-fast: false | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version-file: 'go.mod' | |
- name: Add MSBuild to PATH | |
if: ${{ matrix.os == 'windows' }} | |
uses: microsoft/setup-msbuild@v2 | |
- name: Install WiX | |
if: ${{ matrix.os == 'windows' }} | |
run: dotnet tool install --global wix | |
- name: Package binaries | |
shell: bash | |
run: make 'package-${{ matrix.os }}-${{ matrix.arch }}' | |
- name: Upload artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: '3lv-${{ matrix.os }}-${{ matrix.arch }}' | |
path: 'dist/package/*' | |
pre-release: | |
name: Pre-release | |
needs: [build] | |
runs-on: elvia-runner | |
if: ${{ github.event_name == 'push' }} | |
outputs: | |
version-tag: ${{ steps.get-version.outputs.version_tag }} | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Resolve version | |
id: get-version | |
run: | | |
version=$(cat VERSION) | |
echo "VERSION_TAG=v$version" | tee -a "$GITHUB_ENV" "$GITHUB_OUTPUT" | |
echo "MAJOR_VERSION_TAG=v$(echo $version | cut -d. -f1)" >> "$GITHUB_ENV" | |
- name: Create pre-release if new version | |
id: create-pre-release | |
run: | | |
latest_version=$(gh release list --json name,isLatest -q '.[] | select(.isLatest == true) | .name') | |
if [[ "$latest_version" == "$VERSION_TAG" ]]; then | |
echo "Version already released." | |
exit 0 | |
fi | |
latest_prelrease_version=$(gh release list --json name,isPrerelease -q 'first(.[] | select(.isPrerelease == true) | .name)') | |
if [[ "$latest_prelrease_version" == "$VERSION_TAG" ]]; then | |
echo "Pre-release already created." | |
exit 0 | |
fi | |
gh release create "$VERSION_TAG" --generate-notes --prerelease | |
env: | |
GH_TOKEN: ${{ github.token }} | |
- name: Override old major tag | |
run: | | |
git config user.name github-actions | |
git config user.email github-actions@github.com | |
git fetch --tags | |
git tag "$MAJOR_VERSION_TAG" "$VERSION_TAG" -f | |
git push --tags -f | |
upload-binaries: | |
name: Upload binaries | |
needs: [pre-release] | |
runs-on: elvia-runner | |
if: ${{ github.event_name == 'push' }} | |
strategy: | |
matrix: | |
os: [linux, macos, windows] | |
arch: [amd64] | |
include: | |
- os: macos | |
arch: arm64 | |
fail-fast: false | |
env: | |
VERSION_TAG: ${{ needs.pre-release.outputs.version-tag }} | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Download build artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: '3lv-${{ matrix.os }}-${{ matrix.arch }}' | |
- name: Upload binaries if not already uploaded | |
run: | | |
version=$(echo "$VERSION_TAG" | cut -c 2-) | |
package_name="3lv-$version-${{ matrix.os }}-${{ matrix.arch }}" | |
number_of_binaries=$(gh release view "$VERSION_TAG" \ | |
--json assets \ | |
| jq -r --arg package_name "$package_name" '.[] | map(select(.name | contains($package_name))) | length') | |
# One binary and one checksum file per arch/os combo | |
if [[ "$number_of_binaries" -gt 1 ]]; then | |
echo "Binaries already uploaded." | |
exit 0 | |
fi | |
# Special case for macOS binaries being named differently from their architecture (darwin) | |
if [[ '${{ matrix.os }}' == 'macos' ]]; then | |
mv "3lv-$version-darwin-${{ matrix.arch }}.tar.gz" "$package_name.tar.gz" | |
mv "3lv-$version-darwin-${{ matrix.arch }}.tar.gz.md5" "$package_name.tar.gz.md5" | |
fi | |
# Special case for Windows being packaged as MSI | |
if [[ '${{ matrix.os }}' == 'windows' ]]; then | |
gh release upload "$VERSION_TAG" "$package_name.msi" | |
gh release upload "$VERSION_TAG" "$package_name.msi.md5" | |
else | |
gh release upload "$VERSION_TAG" "$package_name.tar.gz" | |
gh release upload "$VERSION_TAG" "$package_name.tar.gz.md5" | |
fi | |
env: | |
GH_TOKEN: ${{ github.token }} | |
release: | |
name: Release | |
runs-on: elvia-runner | |
needs: [pre-release, upload-binaries] | |
if: ${{ github.event_name == 'push' }} | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Release if new version and not alpha or beta | |
if: ${{ !contains(needs.build.outputs.version-tag, '-alpha') && !contains(needs.build.outputs.version-tag, '-beta') }} | |
run: gh release edit "$VERSION_TAG" --prerelease=false --latest=true | |
env: | |
GH_TOKEN: ${{ github.token }} | |
VERSION_TAG: ${{ needs.pre-release.outputs.version-tag }} |