Files
materialcraft/.gitea/workflows/ci.yml
T
feedc0de 0ce8b96103
Validate, publish and promote materialcraft / validate (push) Successful in 8s
Validate, publish and promote materialcraft / publish (push) Failing after 38s
Use Podman runner for chart publication
2026-12-04 10:14:41 +01:00

114 lines
4.3 KiB
YAML

name: Validate, publish and promote materialcraft
on:
push:
branches: [main]
pull_request:
env:
HELM_VERSION: v4.2.2
CHART_NAME: materialcraft
GITOPS_REPOSITORY: feedc0de/homelab-gitops
IMAGE_REPOSITORY: registry.brunner.ninja/feedc0de/materialcraft
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: linux_amd64
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: azure/setup-helm@v4
with:
version: ${{ env.HELM_VERSION }}
- name: Build immutable image and publish chart
env:
COMMIT_SHA: ${{ gitea.sha }}
QUAY_USERNAME: ${{ secrets.QUAY_USERNAME }}
QUAY_TOKEN: ${{ secrets.QUAY_TOKEN }}
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}"
authfile="${RUNNER_TEMP}/quay-auth.json"
container_id=""
trap 'test -z "${container_id}" || podman rm -f "${container_id}" >/dev/null; rm -f "${authfile}"' EXIT
printf '%s' "${QUAY_TOKEN}" | podman login registry.brunner.ninja \
--authfile "${authfile}" --username "${QUAY_USERNAME}" --password-stdin
podman build --pull=always \
--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
container_id=$(podman run --detach --rm --publish 127.0.0.1:18080:8080 \
"${IMAGE_REPOSITORY}:${CHART_VERSION}")
for attempt in $(seq 1 30); do
if curl --fail --silent http://127.0.0.1:18080/index.html >/dev/null; then break; fi
test "${attempt}" -lt 30
sleep 1
done
podman rm -f "${container_id}" >/dev/null
container_id=""
podman push --authfile "${authfile}" "${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