83 lines
3.3 KiB
YAML
83 lines
3.3 KiB
YAML
name: Validate, publish and promote Factorio chart
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
pull_request:
|
|
concurrency:
|
|
group: factorio-chart-${{ gitea.ref }}
|
|
cancel-in-progress: false
|
|
jobs:
|
|
chart:
|
|
runs-on: linux_amd64
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
- uses: azure/setup-helm@v4
|
|
with:
|
|
version: v4.3.0
|
|
- name: Validate chart and application behavior
|
|
env:
|
|
FACTORIO_SMOKE_TEST: 'true'
|
|
run: |
|
|
python3 -m pip install --target "${RUNNER_TEMP}/python" 'PyYAML==6.0.3'
|
|
export PYTHONPATH="${RUNNER_TEMP}/python"
|
|
echo "PYTHONPATH=${RUNNER_TEMP}/python" >> "${GITHUB_ENV}"
|
|
./test.sh
|
|
./render.sh --namespace factorio > "${RUNNER_TEMP}/factorio.yaml"
|
|
python3 tests/validate.py "${RUNNER_TEMP}/factorio.yaml"
|
|
curl -fsSL https://github.com/yannh/kubeconform/releases/download/v0.7.0/kubeconform-linux-amd64.tar.gz \
|
|
| tar -xz -C "${RUNNER_TEMP}" kubeconform
|
|
"${RUNNER_TEMP}/kubeconform" -strict -ignore-missing-schemas -summary "${RUNNER_TEMP}/factorio.yaml"
|
|
- name: Select chart release version
|
|
if: gitea.ref == 'refs/heads/main'
|
|
run: echo "CHART_VERSION=$(./scripts/chart-version.sh)" >> "${GITHUB_ENV}"
|
|
- name: Package and publish chart
|
|
if: gitea.ref == 'refs/heads/main'
|
|
env:
|
|
PACKAGE_USERNAME: ${{ secrets.PACKAGE_USERNAME }}
|
|
PACKAGE_TOKEN: ${{ secrets.PACKAGE_TOKEN }}
|
|
run: |
|
|
set -euo pipefail
|
|
test -n "$PACKAGE_USERNAME" && test -n "$PACKAGE_TOKEN"
|
|
helm package . --destination "${RUNNER_TEMP}" --version "${CHART_VERSION}"
|
|
curl --fail --silent --show-error --user "$PACKAGE_USERNAME:$PACKAGE_TOKEN" \
|
|
--request POST --upload-file "${RUNNER_TEMP}/factorio-${CHART_VERSION}.tgz" \
|
|
https://code.brunner.ninja/api/packages/feedc0de/helm/api/charts
|
|
- name: Confirm this is still current main
|
|
id: current-main
|
|
if: gitea.ref == 'refs/heads/main'
|
|
env:
|
|
COMMIT_SHA: ${{ gitea.sha }}
|
|
run: |
|
|
git fetch --no-tags origin main
|
|
if test "$(git rev-parse FETCH_HEAD)" = "$COMMIT_SHA"; then
|
|
echo 'promote=true' >> "${GITEA_OUTPUT}"
|
|
else
|
|
echo 'promote=false' >> "${GITEA_OUTPUT}"
|
|
fi
|
|
- uses: actions/checkout@v4
|
|
if: steps.current-main.outputs.promote == 'true'
|
|
with:
|
|
repository: feedc0de/homelab-gitops
|
|
ref: main
|
|
token: ${{ secrets.GITOPS_TOKEN }}
|
|
path: homelab-gitops
|
|
- name: Promote only Factorio's chart version
|
|
if: steps.current-main.outputs.promote == 'true'
|
|
working-directory: homelab-gitops
|
|
run: |
|
|
set -euo pipefail
|
|
./scripts/update-chart-version.sh factorio "${CHART_VERSION}"
|
|
git config user.name feedc0de
|
|
git config user.email feedc0de@users.noreply.code.brunner.ninja
|
|
git add bootstrap/factorio.yaml
|
|
if git diff --cached --quiet; then exit 0; fi
|
|
git commit -m "Deploy Factorio chart ${CHART_VERSION}"
|
|
for attempt in 1 2 3; do
|
|
git push origin HEAD:main && exit 0
|
|
test "$attempt" = 3 && exit 1
|
|
git fetch origin main
|
|
git rebase origin/main
|
|
done
|