Skip to content

Git Release

Git Release #9

Workflow file for this run

name: "Git Release"
permissions:
contents: "write"
on:
workflow_run:
workflows: ["Git Tag"]
types:
- "completed"
env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# name of image
IMAGE: docker-autoheal
# github.repository as <account>/<repo>
IMAGE_NAME: tmknight/docker-autoheal
# cosign version
COSIGN_VER: 'v2.1.1'
# Build args
CONTEXT: .
DISTRO: alpine
RELEASE: stable
jobs:
get-tag:
name: "Get Tag From Package Version"
runs-on: "ubuntu-latest"
outputs:
pkg-version: ${{ steps.pkg-version.outputs.PKG_VERSION }}
steps:
- name: "Check out the repo"
uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: "Get tag"
id: "pkg-version"
shell: "bash"
run: |
echo PKG_VERSION=$(awk -F ' = ' '$1 ~ /^version/ { gsub(/["]/, "", $2); printf("%s",$2) }' Cargo.toml) >> $GITHUB_OUTPUT
create-release:
name: "Create release"
if: ${{ github.event.workflow_run.conclusion == 'success' }}
needs: "get-tag"
runs-on: "ubuntu-latest"
steps:
- name: "Check out the repo"
uses: actions/checkout@v3
- name: "Create release"
uses: "taiki-e/create-gh-release-action@v1"
with:
# (optional) Path to changelog.
# changelog: CHANGELOG.md
branch: "main"
ref: refs/tags/v${{ needs.get-tag.outputs.pkg-version }}
token: ${{ secrets.GITHUB_TOKEN }}
upload-assets:
name: "Upload assets to Github releases"
if: ${{ github.event.workflow_run.conclusion == 'success' }}
needs:
- "get-tag"
- "create-release"
strategy:
matrix:
include:
- target: "x86_64-unknown-linux-gnu"
os: "ubuntu-latest"
- target: "x86_64-unknown-linux-musl"
os: "ubuntu-latest"
- target: "aarch64-unknown-linux-gnu"
os: "ubuntu-latest"
- target: "aarch64-unknown-linux-musl"
os: "ubuntu-latest"
# - target: "aarch64-unknown-openbsd"
# os: "ubuntu-latest"
runs-on: ${{ matrix.os }}
steps:
- name: "Check out the repo"
uses: actions/checkout@v3
- name: "Upload Binaries"
uses: "taiki-e/upload-rust-binary-action@v1"
with:
bin: ${{ env.IMAGE }}
target: ${{ matrix.target }}
archive: $bin-${{ matrix.target }}
ref: refs/tags/v${{ needs.get-tag.outputs.pkg-version }}
token: ${{ secrets.GITHUB_TOKEN }}
push-to-registry:
name: "Publish Docker image"
if: ${{ github.event.workflow_run.conclusion == 'success' }}
needs:
- "get-tag"
- "upload-assets"
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@v3 #v3.1.1
with:
cosign-release: ${{ env.COSIGN_VER }}
# Setup QEMU for multi-arch
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: amd64,arm64
# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v2
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch,enable=${{ github.event_name != 'schedule' }}
type=ref,event=tag
# type=raw,enable=${{ github.event_name == 'schedule' }},value=latest
type=raw,enable=true,value=latest
type=raw,enable=true,value=v${{ needs.get-tag.outputs.pkg-version }}
# type=raw,enable=true,value=${{ env.DISTRO }}-${{ env.RELEASE }}
# type=raw,enable=true,value=${{ env.DISTRO }}
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v4
with:
context: ${{ env.CONTEXT }}
platforms: linux/amd64,linux/arm64
file: docker/${{ env.DISTRO }}/${{ env.RELEASE }}/${{ env.IMAGE }}.dockerfile
build-args: ${{ env.BUILD_ARGS }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
# Sign the resulting Docker image digest except on PRs.
# This will only write to the public Rekor transparency log when the Docker
# repository is public to avoid leaking data. If you would like to publish
# transparency data even for private images, pass --force to cosign below.
# https://github.com/sigstore/cosign
- name: Sign the published Docker image
if: ${{ github.event_name != 'pull_request' }}
env:
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
TAGS: ${{ steps.meta.outputs.tags }}
DIGEST: ${{ steps.build-and-push.outputs.digest }}
# This step uses the identity token to provision an ephemeral certificate
# against the sigstore community Fulcio instance.
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}