Skip to content

chore(ci): build-test pipeline & release prebuilt images #9

chore(ci): build-test pipeline & release prebuilt images

chore(ci): build-test pipeline & release prebuilt images #9

name: template-mage-pipeline
## workflow will trigger on below condition,
## except image release that have jobs condition to trigger only on tagging
on:
pull_request:
branches:
- main
push:
branches:
- main
tags:
- 'v*.*.*'
env:
REGISTRY_URL: us-docker.pkg.dev
jobs:
mage-build-test:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
strategy:
matrix:
go-version: [1.20.x]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Mage - check
uses: magefile/mage-action@v2
with:
version: latest
args: check
- name: Mage - build & test
uses: magefile/mage-action@v2
with:
version: latest
args: test
- name: Docker show build images
run: |
docker image ls -a | grep starter-game-template
- name: Docker save local build images
run: |
docker save ${{ github.event.repository.name }}-nakama:latest > /tmp/${{ github.event.repository.name }}-nakama-latest.tar
docker save ${{ github.event.repository.name }}-cardinal:latest > /tmp/${{ github.event.repository.name }}-cardinal-latest.tar
docker save ${{ github.event.repository.name }}-testsuite:latest > /tmp/${{ github.event.repository.name }}-testsuite-latest.tar
- name: Upload local build images to temporary artifact
uses: actions/upload-artifact@v3
with:
name: buildimage
path: /tmp/starter-game-template-*.tar
images-release:
runs-on: ubuntu-latest
needs: mage-build-test
# if: startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main'
defaults:
run:
shell: bash
# Add "id-token" with the intended permissions.
permissions:
contents: 'read'
id-token: 'write'
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Download local build images artifact
uses: actions/download-artifact@v3
with:
name: buildimage
path: /tmp/
- name: Load image and show build images
run: |
docker load --input /tmp/${{ github.event.repository.name }}-nakama-latest.tar
docker load --input /tmp/${{ github.event.repository.name }}-cardinal-latest.tar
docker load --input /tmp/${{ github.event.repository.name }}-testsuite-latest.tar
docker image ls -a | grep starter-game-template
- name: GCP auth
id: auth
uses: google-github-actions/auth@v1
with:
workload_identity_provider: ${{ secrets.GCP_WIF_PROVIDER }}
service_account: ${{ secrets.GCP_WIF_SERVICE_ACCOUNT }}
- name: GCP - Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v1
with:
project_id: ${{ secrets.GCP_PROJECT_ID }}
- name: Docker - auth to artifact registry
run: |
gcloud auth configure-docker ${{ env.REGISTRY_URL }}
- name: Push image
run: |
IMAGE_ID_NAKAMA=${{ env.REGISTRY_URL }}/${{ github.repository_owner }}/${{ github.event.repository.name }}/nakama
IMAGE_ID_NAKAMA=$(echo $IMAGE_ID_NAKAMA | tr '[A-Z]' '[a-z]')
IMAGE_ID_CARDINAL=${{ env.REGISTRY_URL }}/${{ github.repository_owner }}/${{ github.event.repository.name }}/cardinal
IMAGE_ID_CARDINAL=$(echo $IMAGE_ID_CARDINAL | tr '[A-Z]' '[a-z]')
IMAGE_ID_TESTSUITE=${{ env.REGISTRY_URL }}/${{ github.repository_owner }}/${{ github.event.repository.name }}/testsuite
IMAGE_ID_TESTSUITE=$(echo $IMAGE_ID_TESTSUITE | tr '[A-Z]' '[a-z]')
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
[ "$VERSION" == "main" ] && VERSION=latest
[ "$VERSION" == "merge" ] && VERSION=latest
docker tag ${{ github.event.repository.name }}-nakama:latest $IMAGE_ID_NAKAMA:$VERSION
docker tag ${{ github.event.repository.name }}-cardinal:latest $IMAGE_ID_CARDINAL:$VERSION
docker tag ${{ github.event.repository.name }}-testsuite:latest $IMAGE_ID_TESTSUITE:$VERSION
docker push $IMAGE_ID_NAKAMA:$VERSION
docker push $IMAGE_ID_CARDINAL:$VERSION
docker push $IMAGE_ID_TESTSUITE:$VERSION
artifact-cleanup:
runs-on: ubuntu-latest
needs: [
mage-build-test,
images-release
]
if: always()
steps:
- name: Remove local build image artifact
uses: geekyeggo/delete-artifact@v2
with:
name: buildimage