103 lines
3.6 KiB
YAML
103 lines
3.6 KiB
YAML
name: Validate, publish and promote soundcraft
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
pull_request:
|
|
|
|
env:
|
|
HELM_VERSION: v4.2.2
|
|
CHART_NAME: soundcraft
|
|
GITOPS_REPOSITORY: feedc0de/homelab-gitops
|
|
IMAGE_REPOSITORY: registry.brunner.ninja/feedc0de/soundcraft
|
|
|
|
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 }}
|
|
- 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 }}
|
|
- uses: docker/login-action@v3
|
|
with:
|
|
registry: registry.brunner.ninja
|
|
username: ${{ secrets.QUAY_USERNAME }}
|
|
password: ${{ secrets.QUAY_TOKEN }}
|
|
- name: Build immutable image and publish chart
|
|
env:
|
|
COMMIT_SHA: ${{ gitea.sha }}
|
|
PACKAGE_USERNAME: ${{ secrets.PACKAGE_USERNAME }}
|
|
PACKAGE_TOKEN: ${{ secrets.PACKAGE_TOKEN }}
|
|
run: |
|
|
set -euo pipefail
|
|
CHART_VERSION=$(./scripts/chart-version.sh)
|
|
APP_VERSION=$(sed -n 's/^appVersion: *//p' "chart/${CHART_NAME}/Chart.yaml" | tr -d '"')
|
|
test -n "${APP_VERSION}"
|
|
docker build --pull --load \
|
|
--build-arg "APP_NAME=${CHART_NAME}" \
|
|
--build-arg "APP_VERSION=${APP_VERSION}" \
|
|
--label "org.opencontainers.image.version=${APP_VERSION}" \
|
|
--label "org.opencontainers.image.revision=${COMMIT_SHA}" \
|
|
--tag "${IMAGE_REPOSITORY}:${CHART_VERSION}" image
|
|
docker push "${IMAGE_REPOSITORY}:${CHART_VERSION}"
|
|
install -d dist
|
|
helm package "chart/${CHART_NAME}" --destination dist --version "${CHART_VERSION}"
|
|
curl --fail-with-body \
|
|
--user "${PACKAGE_USERNAME}:${PACKAGE_TOKEN}" \
|
|
--request POST \
|
|
--upload-file "dist/${CHART_NAME}-${CHART_VERSION}.tgz" \
|
|
https://code.brunner.ninja/api/packages/feedc0de/helm/api/charts
|
|
printf 'CHART_VERSION=%s\n' "${CHART_VERSION}" >> "${GITHUB_ENV}"
|
|
- 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
|
|
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: Promote exact chart version
|
|
if: steps.current-main.outputs.promote == 'true'
|
|
working-directory: homelab-gitops
|
|
run: |
|
|
set -euo pipefail
|
|
./scripts/update-chart-version.sh "${CHART_NAME}" "${CHART_VERSION}"
|
|
git config user.name feedc0de
|
|
git config user.email feedc0de@users.noreply.code.brunner.ninja
|
|
git add "bootstrap/${CHART_NAME}.yaml"
|
|
if git diff --cached --quiet; then exit 0; fi
|
|
git commit -m "Deploy ${CHART_NAME} chart ${CHART_VERSION}"
|
|
for attempt in 1 2 3; do
|
|
if git push origin HEAD:main; then exit 0; fi
|
|
test "${attempt}" != 3
|
|
git fetch origin main
|
|
git rebase origin/main
|
|
done
|