Skip to content

CI

CI #67

Workflow file for this run

name: CI
on:
workflow_dispatch:
push:
branches:
- main
jobs:
release:
if: ${{ github.event_name == 'workflow_dispatch' }}
permissions:
id-token: "write"
packages: "write"
name: release
runs-on: ubuntu-24.04
outputs:
tag_name: ${{ steps.draft_release.outputs.tag_name }}
steps:
- name: Checkout
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
fetch-depth: 0
- name: Create GitHub App Token
id: app-token
uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1
with:
app-id: ${{ secrets.VERSION_CLI_UPDATER_APP_ID }}
private-key: ${{ secrets.VERSION_CLI_UPDATER_PRIVATE_KEY }}
- name: Draft release
id: draft_release
uses: release-drafter/release-drafter@b1476f6e6eb133afa41ed8589daba6dc69b4d3f5 # v6.1.0
with:
disable-autolabeler: true
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
- name: Set up QEMU
uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
- name: Get current date
id: date
run: echo "date=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
- name: Extract base image info
id: base_image
run: |
BASE_IMAGE_FULL=$(grep -i '^FROM' Dockerfile | tail -n 1 | awk '{print $2}')
if [[ "$BASE_IMAGE_FULL" == "scratch" ]]; then
echo "name=scratch" >> $GITHUB_OUTPUT
echo "digest=" >> $GITHUB_OUTPUT
else
echo "name=$(echo "$BASE_IMAGE_FULL" | cut -d'@' -f1)" >> $GITHUB_OUTPUT
echo "digest=$(echo "$BASE_IMAGE_FULL" | cut -d'@' -f2)" >> $GITHUB_OUTPUT
fi
- name: Login to GitHub Container Registry
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build Docker image
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
with:
context: .
platforms: |
linux/amd64
linux/arm64
linux/arm/v8
linux/ppc64le
linux/arm/v7
push: true
tags: |
ghcr.io/version-cli/version:latest
ghcr.io/version-cli/version:${{ steps.draft_release.outputs.tag_name }}
labels: |
authors=Koen van Zuijlen <8818390+kvanzuijlen@users.noreply.github.com>
org.opencontainers.image.created=${{ steps.date.outputs.date }}
org.opencontainers.image.authors=Koen van Zuijlen <8818390+kvanzuijlen@users.noreply.github.com>
org.opencontainers.image.url=${{ github.event.repository.html_url }}
org.opencontainers.image.documentation="https://www.version-cli.app"
org.opencontainers.image.source=${{ github.event.repository.html_url }}
org.opencontainers.image.version=${{ steps.draft_release.outputs.tag_name }}
org.opencontainers.image.revision=${{ steps.draft_release.outputs.tag_name }}
org.opencontainers.image.vendor="version-cli"
org.opencontainers.image.licenses=# TODO: add license
org.opencontainers.image.ref.name=${{ steps.draft_release.outputs.tag_name }}
org.opencontainers.image.title=${{ github.event.repository.name }}
org.opencontainers.image.description=${{ github.event.repository.description }}
org.opencontainers.image.base.digest=${{ steps.base_image.outputs.name }}
org.opencontainers.image.base.name=${{ steps.base_image.outputs.digest }}
build-args: |
VERSION=${{ steps.draft_release.outputs.tag_name }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Publish release
uses: release-drafter/release-drafter@b1476f6e6eb133afa41ed8589daba6dc69b4d3f5 # v6.1.0
if: steps.draft_release.outputs.tag_name != ''
with:
version: ${{ steps.draft_release.outputs.tag_name }}
publish: true
disable-autolabeler: true
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
- name: Checkout action code
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
fetch-depth: 0
ref: ${{ steps.draft_release.outputs.tag_name }}
- name: Setup Go environment
uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0
with:
go-version-file: "go.mod"
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0
with:
version: v2.13.2 # renovate: datasource=github-tags depName=goreleaser packageName=goreleaser/goreleaser
args: release --skip=publish --clean
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
GORELEASER_CURRENT_TAG: ${{ steps.draft_release.outputs.tag_name }}
- name: Upload files
run: |
gh release upload --clobber ${{ env.VERSION }} ${{ env.FILES }}
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
VERSION: ${{ steps.draft_release.outputs.tag_name }}
FILES: dist/version_*.tar.gz dist/version_*.zip dist/version_*_checksums.txt
docs-deploy:
runs-on: ubuntu-24.04
if: ${{ always() }}
needs: release
permissions:
contents: write
steps:
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
fetch-depth: 0
- name: Configure Git Credentials
run: |
git config user.name version-cli[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
- name: Install Poetry
env:
poetry_version: 2.2.1 # renovate: datasource=github-tags depName=poetry packageName=python-poetry/poetry
run: pipx install poetry==$poetry_version
- uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
with:
python-version-file: pyproject.toml
cache: "poetry"
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
- uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1
with:
key: mkdocs-material-${{ env.cache_id }}
path: .cache
restore-keys: |
mkdocs-material-
- run: poetry install --no-interaction
- name: Fetch gh-pages remote changes (if any)
run: git fetch origin gh-pages --depth=1
- name: Deploy main docs
if: ${{ github.event_name == 'push' && github.event.ref == 'refs/heads/main' }}
run: poetry run mike deploy --push main
env:
GOOGLE_ANALYTICS_KEY: ${{ secrets.GOOGLE_ANALYTICS_KEY }}
MKDOCS_GIT_COMMITTERS_APIKEY: ${{ github.token }}
EXCLUDE_SHIELDS_IO_PRIVACY: true
VERSION_CLI_VERSION: ${{ needs.release.outputs.tag_name }}
- name: Deploy release docs
if: ${{ github.event_name == 'workflow_dispatch' && needs.release.result == 'success' }}
run: |-
FULL_TAG="${{ needs.release.outputs.tag_name }}"
TAG=$(echo "$FULL_TAG" | sed 's/\.[0-9]*$/\.x/')
poetry run mike deploy --push $TAG
poetry run mike deploy --push latest
env:
GOOGLE_ANALYTICS_KEY: ${{ secrets.GOOGLE_ANALYTICS_KEY }}
MKDOCS_GIT_COMMITTERS_APIKEY: ${{ github.token }}
VERSION_CLI_VERSION: ${{ needs.release.outputs.tag_name }}