Skip to content

Merge pull request #49 from igolman/chore/honor-restic-retention-sett… #27

Merge pull request #49 from igolman/chore/honor-restic-retention-sett…

Merge pull request #49 from igolman/chore/honor-restic-retention-sett… #27

name: "Build, Tag, and Release"
on:
push:
branches:
- main
paths-ignore:
- .gitignore
- .github/renovate.json
- .pre-commit-config.yaml
- LICENSE
- README.MD
- docs/
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-tag-release:
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/main' && github.event_name == 'push' }}
permissions:
contents: write
packages: write
attestations: write
id-token: write
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
fetch-depth: 0
- name: Get next version
id: version
uses: anothrNick/github-tag-action@e528bc2b9628971ce0e6f823f3052d1dcd9d512c # 1.73.0
env:
WITH_V: true
DEFAULT_BUMP: patch
DRY_RUN: true
- name: Check if version changed
id: changed
continue-on-error: true
run: |
if [[ "${{ steps.version.outputs.new_tag }}" == "${{ steps.version.outputs.old_tag }}" ]]; then
echo "Version not changed"
exit 1
else
echo "Version changed"
fi
- name: Install uv
if: ${{ steps.changed.outcome == 'success' }}
uses: astral-sh/setup-uv@bd01e18f51369d5a26f1651c3cb451d3417e3bba # v6
- name: Bump version in files
if: ${{ steps.changed.outcome == 'success' }}
run: |
version="${{ steps.version.outputs.new_tag }}"
clean_version="${version#v}"
sed -i "s/__version__ = .*/__version__ = \"${clean_version}\"/" src/restic_compose_backup/__init__.py
sed -i "s/version = .*/version = \"${clean_version}\"/" src/pyproject.toml
sed -i "s/release = .*/release = \"${clean_version}\"/" docs/conf.py
uv lock --directory src --upgrade-package restic-compose-backup
- name: Push version tag
if: ${{ steps.changed.outcome == 'success' }}
uses: anothrNick/github-tag-action@e528bc2b9628971ce0e6f823f3052d1dcd9d512c # 1.73.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CUSTOM_TAG: ${{ steps.version.outputs.new_tag }}
- name: Log in to the Container registry
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3
- name: Generate metadata for published image
id: meta
run: |
TAG=${{ steps.version.outputs.new_tag }}
echo "version=${TAG#v}" >> $GITHUB_OUTPUT
echo "timestamp=$(date -u +'%Y-%m-%dT%H:%M:%S.000Z')" >> $GITHUB_OUTPUT
- name: Build and push Docker image
id: push
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6
with:
context: src/
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }}
${{ steps.changed.outcome == 'success' && format('{0}/{1}:latest', env.REGISTRY, env.IMAGE_NAME) || null }}
${{ steps.changed.outcome == 'success' && format('{0}/{1}:{2}', env.REGISTRY, env.IMAGE_NAME, steps.version.outputs.new_tag) || null }}
labels: |
org.opencontainers.image.title=${{ github.event.repository.name }}
org.opencontainers.image.url=${{ github.repositoryUrl }}
org.opencontainers.image.source=${{ github.repositoryUrl }}
org.opencontainers.image.version=${{ steps.meta.outputs.version }}
org.opencontainers.image.revision=${{ steps.commit.outputs.commit_hash }}
org.opencontainers.image.created=${{ steps.meta.outputs.timestamp }}
- name: Generate artifact attestation
uses: actions/attest-build-provenance@e8998f949152b193b063cb0ec769d69d929409be # v2
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
- name: Update release
if: ${{ steps.changed.outcome == 'success' }}
uses: ncipollo/release-action@440c8c1cb0ed28b9f43e4d1d670870f059653174 # v1
with:
allowUpdates: true
updateOnlyUnreleased: true
generateReleaseNotes: true
tag: ${{ steps.version.outputs.new_tag }}