Skip to content

Feat/testsemanticversioning (#112) #384

Feat/testsemanticversioning (#112)

Feat/testsemanticversioning (#112) #384

name: Build and publish Docker image to quay.io
on:
push:
branches:
- 'develop'
- 'main'
pull_request:
env:
REPOSITORY: quay.io/sdase/image-metadata-collector
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout branch
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "lts/*"
- name: Install Semantic release
run: |
sudo npm install -g \
semantic-release@18.0.0 \
@semantic-release/git@10.0.0 \
@semantic-release/release-notes-generator@10.0.2 \
@semantic-release/github@8.0.0
- name: Release Dry
id: semantic-release-dry
run: semantic-release --dry-run >> output.txt ; cat output.txt; echo "VERSION=$(cat output.txt | grep 'Release note for version' | grep -oP '\d+\.\d+\.\d+')" >> $GITHUB_ENV
env:
GITHUB_TOKEN: "${{ secrets.GH_PUBLISH_TOKEN_ID }}"
- name: Get Semantic Release Version
id: get-version
run: |
branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
sanitized_branch=$(echo "${branch}" | tr '/' '-')
if [ "${branch}" == "main" ]; then
if [ -z "${{ steps.semantic-release-dry.outputs.VERSION }}" ]; then
echo "semantic release not detecting a new version, using latest tag"
VERSION=$(git describe --tags --abbrev=0)
else
VERSION=${{ steps.semantic-release-dry.outputs.VERSION }}
fi
echo "::set-output name=version::$VERSION"
else
echo "::set-output name=version::${sanitized_branch}"
fi
# TODO: Discuss testing strategy and change this step accordingly
# e.g. Test in Docker Image, Kind Cluster, ...
- name: Set up Go for Tests
uses: actions/setup-go@v5
with:
go-version: 1.21
- name: Test with Go
run: go test ./...
# Add support for more platforms with QEMU (optional)
# https://github.com/docker/setup-qemu-action
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Quay.io
uses: docker/login-action@v3
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_ROBOT_TOKEN }}
- name: Build image and push to Quay.io
uses: docker/build-push-action@v5
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ env.REPOSITORY }}:${{ steps.get-version.outputs.version }}
- name: Release and Publish
run: semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GH_PUBLISH_TOKEN_ID }}