dad3132fdb
CI / build-and-push (push) Failing after 6s
CI / deploy-dev (push) Has been skipped
CI / deploy-uat (push) Has been skipped
CI / build-and-push (pull_request) Has been skipped
CI / deploy-dev (pull_request) Has been skipped
CI / deploy-uat (pull_request) Has been skipped
Replace ${{ secrets.GITHUB_TOKEN }} with ${{ secrets.GITEA_TOKEN }}
for docker/login-action in Gitea Actions. GITHUB_TOKEN is not available
in Gitea Actions and was causing 'authentication required' failures for
ghcr.io push, leaving the auth service with a stale image on UAT.
Co-Authored-By: Paperclip <noreply@paperclip.ing>
155 lines
4.9 KiB
YAML
155 lines
4.9 KiB
YAML
name: CI
|
|
|
|
on:
|
|
push:
|
|
branches: [main, dev, uat]
|
|
pull_request:
|
|
branches: [main, dev, uat]
|
|
|
|
concurrency:
|
|
group: ci-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
permissions:
|
|
contents: write
|
|
packages: write
|
|
security-events: write
|
|
|
|
env:
|
|
REGISTRY: ghcr.io
|
|
IMAGE_NAME: cartsnitch/auth
|
|
|
|
jobs:
|
|
build-and-push:
|
|
runs-on: ubuntu-latest
|
|
if: github.event_name == 'push'
|
|
outputs:
|
|
calver_tag: ${{ steps.calver.outputs.version }}
|
|
sha_tag: sha-${{ github.sha }}
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Generate CalVer tag
|
|
id: calver
|
|
if: github.ref == 'refs/heads/main'
|
|
run: |
|
|
DATE_TAG=$(date -u +%Y.%m.%d)
|
|
EXISTING=$(git tag -l "v${DATE_TAG}*" | sort -V | tail -1)
|
|
if [ -z "$EXISTING" ]; then VERSION="$DATE_TAG"
|
|
elif [ "$EXISTING" = "v${DATE_TAG}" ]; then VERSION="${DATE_TAG}.2"
|
|
else BUILD_NUM=$(echo "$EXISTING" | sed "s/v${DATE_TAG}\.//"); VERSION="${DATE_TAG}.$((BUILD_NUM + 1))"; fi
|
|
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Log in to GHCR
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITEA_TOKEN }}
|
|
|
|
- name: Extract metadata
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
tags: |
|
|
type=sha,prefix=sha-,format=long
|
|
type=raw,value=${{ steps.calver.outputs.version }},enable=${{ github.ref == 'refs/heads/main' }}
|
|
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
|
|
|
|
- name: Build and push Docker image
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
push: true
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
|
|
- name: Create git tag
|
|
if: github.ref == 'refs/heads/main'
|
|
run: |
|
|
git tag "v${{ steps.calver.outputs.version }}"
|
|
git push origin "v${{ steps.calver.outputs.version }}"
|
|
|
|
deploy-dev:
|
|
runs-on: ubuntu-latest
|
|
needs: [build-and-push]
|
|
if: github.event_name == 'push' && (github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/main')
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
repository: cartsnitch/infra
|
|
token: ${{ secrets.GITEA_TOKEN }}
|
|
ref: main
|
|
path: infra
|
|
|
|
- uses: imranismail/setup-kustomize@v2
|
|
|
|
- name: Determine image tag
|
|
id: tag
|
|
run: |
|
|
if [ "${{ github.ref }}" == "refs/heads/main" ]; then
|
|
echo "tag=${{ needs.build-and-push.outputs.calver_tag }}" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "tag=${{ needs.build-and-push.outputs.sha_tag }}" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
- name: Update auth image tag in dev overlay
|
|
run: |
|
|
cd infra/apps/overlays/dev
|
|
kustomize edit set image ghcr.io/cartsnitch/auth:${{ steps.tag.outputs.tag }}
|
|
|
|
- name: Commit and push to infra
|
|
run: |
|
|
cd infra
|
|
git config user.name "cartsnitch-ci[bot]"
|
|
git config user.email "cartsnitch-ci[bot]@users.noreply.github.com"
|
|
git add apps/overlays/dev/kustomization.yaml
|
|
git diff --cached --quiet && echo "No changes" && exit 0
|
|
git commit -m "ci(dev): update auth image from cartsnitch/auth CI"
|
|
git pull --rebase origin main
|
|
git push origin main
|
|
|
|
deploy-uat:
|
|
runs-on: ubuntu-latest
|
|
needs: [build-and-push]
|
|
if: github.event_name == 'push' && (github.ref == 'refs/heads/uat' || github.ref == 'refs/heads/main')
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
repository: cartsnitch/infra
|
|
token: ${{ secrets.GITEA_TOKEN }}
|
|
ref: main
|
|
path: infra
|
|
|
|
- uses: imranismail/setup-kustomize@v2
|
|
|
|
- name: Determine image tag
|
|
id: tag
|
|
run: |
|
|
if [ "${{ github.ref }}" == "refs/heads/main" ]; then
|
|
echo "tag=${{ needs.build-and-push.outputs.calver_tag }}" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "tag=${{ needs.build-and-push.outputs.sha_tag }}" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
- name: Update auth image tag in uat overlay
|
|
run: |
|
|
cd infra/apps/overlays/uat
|
|
kustomize edit set image ghcr.io/cartsnitch/auth:${{ steps.tag.outputs.tag }}
|
|
|
|
- name: Commit and push to infra
|
|
run: |
|
|
cd infra
|
|
git config user.name "cartsnitch-ci[bot]"
|
|
git config user.email "cartsnitch-ci[bot]@users.noreply.github.com"
|
|
git add apps/overlays/uat/kustomization.yaml
|
|
git diff --cached --quiet && echo "No changes" && exit 0
|
|
git commit -m "ci(uat): update auth image from cartsnitch/auth CI"
|
|
git pull --rebase origin main
|
|
git push origin main
|