Canary Release #3
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: Canary Release | |
on: | |
workflow_dispatch: | |
jobs: | |
build-and-push: | |
name: Build and Push Docker Images | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
packages: write | |
id-token: write | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Log in to GHCR | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Get Latest Canary Version | |
id: get-version | |
run: | | |
latest_tag=$(git tag --sort=-v:refname | grep 'v1\.0\.0-canary\.' | head -n 1) | |
if [ -z "$latest_tag" ]; then | |
next_version="v1.0.0-canary.1" | |
else | |
latest_number=${latest_tag##*.} | |
next_number=$((latest_number+1)) | |
next_version="v1.0.0-canary.$next_number" | |
fi | |
echo "next_version=$next_version" >> $GITHUB_OUTPUT | |
- name: Build and Push Images | |
run: | | |
apps=("web" "api" "sync") | |
git_sha=${GITHUB_SHA::7} | |
for app in "${apps[@]}"; do | |
image="ghcr.io/avelinapp/$app" | |
tags=( | |
"canary" | |
"v1.0.0-canary" | |
"${{ steps.get-version.outputs.next_version }}" | |
"$git_sha" | |
) | |
tag_args="" | |
for tag in "${tags[@]}"; do | |
tag_args="$tag_args -t $image:$tag" | |
done | |
docker buildx build -f "apps/$app/Dockerfile" $tag_args --push . | |
done | |
- name: Create Canary Tag | |
run: | | |
git config user.name "${{ github.actor }}" | |
git config user.email "${{ github.actor }}@users.noreply.github.com" | |
git tag ${{ steps.get-version.outputs.next_version }} | |
git push origin ${{ steps.get-version.outputs.next_version }} |