Skip to content

chore: merge upstream #1

chore: merge upstream

chore: merge upstream #1

Workflow file for this run

name: Build & Release
on:
workflow_dispatch:
pull_request:
branches:
- master
- develop
paths:
- "src/**"
- "data/**"
push:
branches:
- master
- develop
paths:
- "src/**"
- "data/**"
jobs:
release:
runs-on: ubuntu-latest
outputs:
release-version: ${{ steps.extract_version.outputs.RELEASE_VERSION }}
is-prerelease: ${{ steps.prerelease_check.outputs.IS_PRERELEASE }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Use Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: '20.x'
- name: Install Semantic Release
run: |
npm install semantic-release @semantic-release/github --save-dev
npm install conventional-changelog-eslint --save-dev
# https://github.com/semantic-release/semantic-release/issues/1592#issuecomment-902533435
# Semantic-release doesn't support pathing to a config file unless using a .js config,
# instead copy the file to the root as a workaround to maintain workflow separation.
- name: Copy Release Config to Root
run: |
cp .github/.releaserc ./
# Ensure that only one rc pre-release is active at a time by deleting the latest pre-release
# and its corresponding tag on the 'develop' branch. This avoids clutter from multiple rc
# releases after each merge into the develop branch.
- name: Delete Existing Pre-release and Tag (Develop Branch Only)
if: github.ref == 'refs/heads/develop'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
latest_prerelease_tag=$(gh release list --limit 1 --json tagName,isPrerelease \
--jq '.[] | select(.isPrerelease) | .tagName')
if [ -n "$latest_prerelease_tag" ]; then
gh release delete "$latest_prerelease_tag" --yes --cleanup-tag
fi
- name: Semantic Release (Dry Run for PRs)
if: ${{ github.event_name == 'pull_request' }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npx semantic-release --ci --dry-run
- name: Semantic Release (Full Release on Push)
id: semantic_release
if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DEBUG: semantic-release:*
run: npx semantic-release --ci
# https://semantic-release.gitbook.io/semantic-release/usage/workflow-configuration#pre-release-branches
# Semantic-release appends a numerical suffix to all pre-releases by default (e.g., `v0.0.1-rc.1`).
# Currently, this behavior is not configurable via CLI or the release config. For improved readability
# and consistency, this step renames the tag and associated release by removing the numerical suffix
# from the rc pre-release (e.g., renaming `v0.0.1-rc.1` to `v0.0.1-rc`).
- name: Rename Release Candidate Release Tag (Develop Branch Only)
if: github.ref == 'refs/heads/develop'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
latest_tag=$(gh release list --limit 1 --json tagName,isPrerelease --jq '.[] | select(.isPrerelease) | .tagName')
if [[ $latest_tag == *"-rc."* ]]; then
new_tag=${latest_tag%-rc.*}-rc
new_name="Release ${new_tag}"
gh release edit "$latest_tag" --tag "$new_tag" --title "$new_name"
git tag $new_tag $latest_tag # Create the new tag pointing to the same commit
git tag -d $latest_tag # Delete the old tag locally
git push origin $new_tag # Push the new tag to the remote
git push origin :refs/tags/$latest_tag # Delete the old tag on the remote
fi
- name: Extract Release Version
id: extract_version
run: |
VERSION=$(git describe --tags --abbrev=0)
echo "RELEASE_VERSION=${VERSION}" >> $GITHUB_OUTPUT
- name: Determine if Pre-release
id: prerelease_check
run: |
if [[ "${{ steps.extract_version.outputs.RELEASE_VERSION }}" == *"-"* ]]; then
echo "IS_PRERELEASE=true" >> $GITHUB_OUTPUT
else
echo "IS_PRERELEASE=false" >> $GITHUB_OUTPUT
fi
build:
runs-on: ubuntu-latest
needs: release
permissions:
packages: write
strategy:
matrix:
platform: [linux/amd64, linux/arm64]
include:
- platform: linux/amd64
release_arch: release_64
- platform: linux/arm64
release_arch: release_arm64
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
install: true
driver-opts: image=moby/buildkit:latest,network=host
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Restore vcpkg cache
uses: actions/cache@v3
with:
path: /bts/vcpkg/installed
key: vcpkg-${{ runner.os }}-${{ hashFiles('vcpkg.json') }}
restore-keys: |
vcpkg-${{ runner.os }}-
# Build a comma-separated list of tags.. Always tag the image with the specific release
# version (e.g., ghcr.io/xx/xx:v1.0.0). If the release is a pre-release (e.g.: alpha/beta),
# add an 'rc' tag to mark it as a release candidate. If the release is a stable release, add
# the 'latest' tag to denote the most recent stable version.
- name: Set Image Tags
id: set_tags
run: |
IMAGE_TAGS="ghcr.io/${{ github.repository }}:${{ needs.release.outputs.release-version }}"
if [ "${{ needs.release.outputs.is-prerelease }}" = "true" ]; then
IMAGE_TAGS="$IMAGE_TAGS,ghcr.io/${{ github.repository }}:rc"
else
IMAGE_TAGS="$IMAGE_TAGS,ghcr.io/${{ github.repository }}:latest"
fi
echo "IMAGE_TAGS=${IMAGE_TAGS}" >> $GITHUB_OUTPUT
- name: Restore Docker layer cache
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: docker-cache-${{ runner.os }}-${{ matrix.platform }}-${{ hashFiles('Dockerfile', 'src/**') }}
restore-keys: |
docker-cache-${{ runner.os }}-${{ matrix.platform }}-
- name: Build Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.set_tags.outputs.IMAGE_TAGS }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: ${{ matrix.platform }}
build-args: |
RELEASE_ARCH=${{ matrix.release_arch }}