87 lines
2.9 KiB
YAML
87 lines
2.9 KiB
YAML
name: Validate, publish and promote Asciinema chart
|
|
|
|
on:
|
|
push:
|
|
pull_request:
|
|
|
|
env:
|
|
HELM_VERSION: v4.2.2
|
|
KUBECONFORM_VERSION: v0.7.0
|
|
GITOPS_REPOSITORY: feedc0de/homelab-gitops
|
|
|
|
jobs:
|
|
validate:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
- uses: azure/setup-helm@v4
|
|
with:
|
|
version: ${{ env.HELM_VERSION }}
|
|
- name: Lint, render and validate the chart
|
|
run: ./test.sh
|
|
|
|
publish:
|
|
if: gitea.ref == 'refs/heads/main'
|
|
needs: validate
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
- uses: azure/setup-helm@v4
|
|
with:
|
|
version: ${{ env.HELM_VERSION }}
|
|
- name: Select immutable chart version
|
|
run: printf 'CHART_VERSION=%s\n' "$(./scripts/chart-version.sh)" >> "$GITHUB_ENV"
|
|
- name: Package and publish chart
|
|
env:
|
|
PACKAGE_USERNAME: ${{ secrets.PACKAGE_USERNAME }}
|
|
PACKAGE_TOKEN: ${{ secrets.PACKAGE_TOKEN }}
|
|
run: |
|
|
set -euo pipefail
|
|
test -n "$PACKAGE_USERNAME"
|
|
test -n "$PACKAGE_TOKEN"
|
|
mkdir -p .chart-packages
|
|
helm package chart/asciinema --destination .chart-packages --version "$CHART_VERSION"
|
|
curl --fail --silent --show-error --user "$PACKAGE_USERNAME:$PACKAGE_TOKEN" \
|
|
--request POST --upload-file ".chart-packages/asciinema-$CHART_VERSION.tgz" \
|
|
https://code.brunner.ninja/api/packages/feedc0de/helm/api/charts
|
|
- name: Check that this is still current main
|
|
id: current-main
|
|
env:
|
|
COMMIT_SHA: ${{ gitea.sha }}
|
|
run: |
|
|
git fetch --no-tags origin main
|
|
if [ "$(git rev-parse FETCH_HEAD)" = "$COMMIT_SHA" ]; then
|
|
echo 'promote=true' >> "$GITEA_OUTPUT"
|
|
else
|
|
echo 'promote=false' >> "$GITEA_OUTPUT"
|
|
fi
|
|
- name: Check out GitOps repository
|
|
if: steps.current-main.outputs.promote == 'true'
|
|
uses: actions/checkout@v4
|
|
with:
|
|
repository: ${{ env.GITOPS_REPOSITORY }}
|
|
ref: main
|
|
token: ${{ secrets.GITOPS_TOKEN }}
|
|
path: homelab-gitops
|
|
- name: Commit chart promotion
|
|
if: steps.current-main.outputs.promote == 'true'
|
|
working-directory: homelab-gitops
|
|
run: |
|
|
set -euo pipefail
|
|
./scripts/update-chart-version.sh asciinema "$CHART_VERSION"
|
|
git config user.name feedc0de
|
|
git config user.email feedc0de@users.noreply.code.brunner.ninja
|
|
git add bootstrap/asciinema.yaml
|
|
if git diff --cached --quiet; then exit 0; fi
|
|
git commit -m "Deploy asciinema chart $CHART_VERSION"
|
|
for attempt in 1 2 3; do
|
|
git push origin HEAD:main && exit 0
|
|
[ "$attempt" = 3 ] && exit 1
|
|
git fetch origin main
|
|
git rebase origin/main
|
|
done
|