Skip to content

ci: match Pages artifact format #81

ci: match Pages artifact format

ci: match Pages artifact format #81

Workflow file for this run

name: Release
on:
push:
branches: [ master ]
permissions:
contents: write
packages: write
jobs:
generate-version:
runs-on: ubuntu-latest
name: Generate Semantic Version
outputs:
new_tag: ${{ steps.tag_version.outputs.new_tag }}
new_version: ${{ steps.tag_version.outputs.new_version }}
changelog: ${{ steps.tag_version.outputs.changelog }}
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Bump version and push tag
id: tag_version
run: |
latest_tag="$(git tag -l 'v*' --sort=-version:refname | head -n1)"
if [ -z "$latest_tag" ]; then
latest_tag="v0.0.0"
fi
version="${latest_tag#v}"
major="${version%%.*}"
rest="${version#*.}"
minor="${rest%%.*}"
patch="${rest##*.}"
next_patch=$((patch + 1))
new_version="${major}.${minor}.${next_patch}"
new_tag="v${new_version}"
git tag "${new_tag}"
git push origin "${new_tag}"
if [ "${latest_tag}" = "v0.0.0" ]; then
changelog="$(git log --pretty=format:'- %s (%h)')"
else
changelog="$(git log --pretty=format:'- %s (%h)' "${latest_tag}..HEAD")"
fi
{
echo "new_tag=${new_tag}"
echo "new_version=${new_version}"
echo "changelog<<EOF"
printf '%s\n' "${changelog}"
echo "EOF"
} >> "${GITHUB_OUTPUT}"
build-and-push-image:
needs: generate-version
runs-on: ubuntu-latest
name: Build & Push Container Image
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
with:
platforms: linux/amd64,linux/arm64
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to Container Registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v6
with:
images: ghcr.io/moolen/spectre
tags: |
type=raw,value=${{ needs.generate-version.outputs.new_tag }}
type=raw,value=${{ needs.generate-version.outputs.new_version }}
type=raw,value=latest
type=ref,event=branch
type=sha,prefix={{branch}}-
- name: Build and push Docker image
uses: docker/build-push-action@v7
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VERSION=${{ needs.generate-version.outputs.new_version }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-and-push-helm-chart:
runs-on: ubuntu-latest
name: Build & Push Helm Chart
needs: [generate-version, build-and-push-image]
outputs:
chart_package: ${{ steps.package.outputs.chart_package }}
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Install Helm
run: |
HELM_VERSION="v3.13.0"
curl -fsSL "https://get.helm.sh/helm-${HELM_VERSION}-linux-amd64.tar.gz" -o /tmp/helm.tgz
tar -C /tmp -xzf /tmp/helm.tgz
sudo install /tmp/linux-amd64/helm /usr/local/bin/helm
helm version
- name: Install yq
run: |
sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
sudo chmod +x /usr/local/bin/yq
- name: Update Chart version and appVersion
run: |
VERSION=${{ needs.generate-version.outputs.new_version }}
yq eval ".version = \"${VERSION}\"" -i chart/Chart.yaml
yq eval ".appVersion = \"${VERSION}\"" -i chart/Chart.yaml
yq eval ".image.repository = \"ghcr.io/moolen/spectre\"" -i chart/values.yaml
yq eval ".image.tag = \"${VERSION}\"" -i chart/values.yaml
- name: Log in to Container Registry
run: |
echo ${{ secrets.GITHUB_TOKEN }} | helm registry login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Package Helm chart
id: package
run: |
helm package ./chart
VERSION=${{ needs.generate-version.outputs.new_version }}
echo "chart_package=spectre-${VERSION}.tgz" >> $GITHUB_OUTPUT
- name: Push Helm chart to OCI
run: |
helm push ${{ steps.package.outputs.chart_package }} oci://ghcr.io/moolen/charts
- name: Upload chart as artifact
uses: actions/upload-artifact@v4
with:
name: helm-chart
path: ${{ steps.package.outputs.chart_package }}
retention-days: 5
- name: Log out from Container Registry
if: always()
run: helm registry logout ghcr.io
create-github-release:
runs-on: ubuntu-latest
name: Create GitHub Release
needs: [generate-version, build-and-push-helm-chart]
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Download Helm chart artifact
uses: actions/download-artifact@v4
with:
name: helm-chart
- name: Create GitHub Release
uses: ncipollo/release-action@v1
with:
tag: ${{ needs.generate-version.outputs.new_tag }}
name: Release ${{ needs.generate-version.outputs.new_tag }}
body: |
## What's Changed
${{ needs.generate-version.outputs.changelog }}
## Container Images
```bash
docker pull ghcr.io/moolen/spectre:${{ needs.generate-version.outputs.new_version }}
```
## Helm Chart
```bash
helm install spectre oci://ghcr.io/moolen/charts/spectre --version ${{ needs.generate-version.outputs.new_version }}
```
artifacts: ${{ needs.build-and-push-helm-chart.outputs.chart_package }}
generateReleaseNotes: true
makeLatest: true