124 lines
4.6 KiB
YAML
124 lines
4.6 KiB
YAML
name: Test and publish Homegate
|
|
"on":
|
|
push:
|
|
branches: ['**']
|
|
tags: ['v*']
|
|
pull_request:
|
|
|
|
# Use a Linux runner labelled ubuntu-latest; see REGISTRY.md.
|
|
permissions:
|
|
contents: read
|
|
|
|
jobs:
|
|
checks:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: https://github.com/actions/checkout@v4
|
|
with:
|
|
github-server-url: ${{ gitea.server_url }}
|
|
token: ${{ secrets.GITEA_TOKEN }}
|
|
persist-credentials: false
|
|
- name: Python environment
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
test_env="$(mktemp -d "$RUNNER_TEMP/homegate-python.XXXXXX")"
|
|
printf 'TEST_PYTHON=%s/bin/python\n' "$test_env" >> "$GITHUB_ENV"
|
|
printf 'TEST_ENV=%s\n' "$test_env" >> "$GITHUB_ENV"
|
|
python3 -m venv "$test_env"
|
|
"$test_env/bin/python" -m pip install -r requirements.txt
|
|
- name: Unit and HTTP tests
|
|
run: '"$TEST_PYTHON" -m unittest discover -s tests -v'
|
|
- name: JavaScript and shell syntax
|
|
run: |
|
|
node --check ui/dist/app.js
|
|
node --check ui/dist/settings.js
|
|
node --check ui/dist/certificates.js
|
|
for script in setup.sh run-local.sh ci/smoke_image.sh; do sh -n "$script"; done
|
|
- name: Compose contracts
|
|
env:
|
|
PYTHONPATH: .
|
|
run: '"$TEST_PYTHON" ci/check_compose.py'
|
|
- name: Build image
|
|
env:
|
|
CI_REVISION: ${{ gitea.sha }}
|
|
run: |
|
|
set -eu
|
|
build_image="homegate-ci:$CI_REVISION-$$"
|
|
trap 'docker image rm "$build_image" >/dev/null 2>&1 || true' EXIT
|
|
docker build --build-arg VERSION="$(cat VERSION)" --tag "$build_image" .
|
|
- name: Clean Python environment
|
|
if: always()
|
|
shell: bash
|
|
run: |
|
|
if [ -n "${TEST_ENV:-}" ]; then rm -rf -- "$TEST_ENV"; fi
|
|
|
|
publish:
|
|
needs: checks
|
|
if: gitea.event_name == 'push' && startsWith(gitea.ref, 'refs/tags/v')
|
|
runs-on: ubuntu-latest
|
|
env:
|
|
DOCKER_BUILD_SUMMARY: "false"
|
|
DOCKER_BUILD_RECORD_UPLOAD: "false"
|
|
steps:
|
|
- name: Validate registry credentials
|
|
shell: bash
|
|
env:
|
|
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
|
|
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
|
run: |
|
|
set -euo pipefail
|
|
missing=0
|
|
if [ -z "${REGISTRY_USERNAME:-}" ]; then
|
|
echo "::error::Missing Actions secret REGISTRY_USERNAME. Set it in Repository Settings > Actions > Secrets to the Gitea username that owns REGISTRY_TOKEN."
|
|
missing=1
|
|
fi
|
|
if [ -z "${REGISTRY_TOKEN:-}" ]; then
|
|
echo "::error::Missing Actions secret REGISTRY_TOKEN. Set it in Repository Settings > Actions > Secrets to a Gitea personal access token with write:package permission. Actions Variables and runner environment variables do not populate secrets.REGISTRY_TOKEN."
|
|
missing=1
|
|
fi
|
|
exit "$missing"
|
|
- name: Checkout release
|
|
uses: https://github.com/actions/checkout@v4
|
|
with:
|
|
github-server-url: ${{ gitea.server_url }}
|
|
token: ${{ secrets.GITEA_TOKEN }}
|
|
persist-credentials: false
|
|
- name: Validate release identity
|
|
id: image
|
|
env:
|
|
CI_SERVER_URL: ${{ gitea.server_url }}
|
|
CI_REPOSITORY: ${{ gitea.repository }}
|
|
CI_REF: ${{ gitea.ref }}
|
|
CI_REVISION: ${{ gitea.sha }}
|
|
REGISTRY: ${{ vars.REGISTRY }}
|
|
run: python3 ci/image_metadata.py
|
|
- name: Configure cross-platform emulation
|
|
uses: https://github.com/docker/setup-qemu-action@v3
|
|
with:
|
|
platforms: amd64,arm64
|
|
- name: Configure Buildx
|
|
uses: https://github.com/docker/setup-buildx-action@v3
|
|
- name: Log in to Gitea Container Registry
|
|
uses: https://github.com/docker/login-action@v3
|
|
with:
|
|
registry: ${{ steps.image.outputs.registry }}
|
|
username: ${{ secrets.REGISTRY_USERNAME }}
|
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
- name: Publish AMD64 and ARM64 image
|
|
uses: https://github.com/docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
platforms: linux/amd64,linux/arm64
|
|
push: true
|
|
build-args: |
|
|
VERSION=${{ steps.image.outputs.version }}
|
|
tags: |
|
|
${{ steps.image.outputs.image }}:${{ steps.image.outputs.version }}
|
|
${{ steps.image.outputs.image }}:sha-${{ steps.image.outputs.revision }}
|
|
labels: |
|
|
org.opencontainers.image.source=${{ steps.image.outputs.source }}
|
|
org.opencontainers.image.revision=${{ steps.image.outputs.revision }}
|
|
provenance: false
|