-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #93 from swisstopo/LGVISIUM-92-Add-Github-workflow…
…-to-match-the-deployment-expectations-from-Geowerkstatt Close #LGVISIUM-92: Add GitHub actions and push Docker images to GHCR
- Loading branch information
Showing
10 changed files
with
273 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
name: Pre-release | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
workflow_dispatch: | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
jobs: | ||
create-pre-release: | ||
runs-on: ubuntu-latest | ||
name: Build and push Docker image and create a new GitHub pre-release | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set environment variables | ||
run: | | ||
echo VERSION=$(cat VERSION).$GITHUB_RUN_NUMBER >> $GITHUB_ENV | ||
echo BASE_IMAGE_NAME=$REGISTRY/$(echo ${GITHUB_REPOSITORY,,}) >> $GITHUB_ENV | ||
echo COMMITED_AT=$(git show -s --format=%cI `git rev-parse HEAD`) >> $GITHUB_ENV | ||
- name: Collect Docker image metadata (api) | ||
id: meta-api | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ env.BASE_IMAGE_NAME }}-api | ||
labels: | | ||
org.opencontainers.image.created=${{ env.COMMITED_AT }} | ||
org.opencontainers.image.version=v${{ env.VERSION }} | ||
org.opencontainers.image.authors=Stijn Vermeeren <[email protected]> | ||
flavor: | | ||
latest=false | ||
tags: | | ||
type=edge | ||
type=semver,pattern=v{{version}},value=${{ env.VERSION }} | ||
- name: Log in to the GitHub container registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Build and push Docker image (api) | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: ./ | ||
push: true | ||
build-args: | | ||
VERSION=${{ env.VERSION }} | ||
tags: ${{ steps.meta-api.outputs.tags }} | ||
labels: ${{ steps.meta-api.outputs.labels }} | ||
cache-from: type=registry,ref=${{ env.BASE_IMAGE_NAME }}-api:edge | ||
cache-to: type=inline | ||
|
||
- name: Create GitHub pre-release | ||
run: | | ||
gh api \ | ||
--method POST \ | ||
--header "Accept: application/vnd.github+json" \ | ||
/repos/${GITHUB_REPOSITORY}/releases \ | ||
-f tag_name='v${{ env.VERSION }}' \ | ||
-f target_commitish='main' \ | ||
-f name='${{ env.VERSION }}' \ | ||
-F prerelease=true \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
name: Release | ||
|
||
on: | ||
release: | ||
types: [released] | ||
workflow_dispatch: | ||
inputs: | ||
TAG_NAME: | ||
description: "Tag name" | ||
required: true | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
TAG_NAME: ${{ github.event.inputs.TAG_NAME || github.event.release.tag_name }} | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
jobs: | ||
retag-docker-image: | ||
runs-on: ubuntu-latest | ||
name: Push updated Docker image | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set environment variables | ||
run: | | ||
echo VERSION=${TAG_NAME#v} >> $GITHUB_ENV | ||
echo BASE_IMAGE_NAME=$REGISTRY/$(echo ${GITHUB_REPOSITORY,,}) >> $GITHUB_ENV | ||
echo COMMITED_AT=$(git show -s --format=%cI `git rev-parse HEAD`) >> $GITHUB_ENV | ||
- name: Collect Docker image metadata (api) | ||
id: meta-api | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ env.BASE_IMAGE_NAME }}-api | ||
labels: | | ||
org.opencontainers.image.created=${{ env.COMMITED_AT }} | ||
org.opencontainers.image.version=v${{ env.VERSION }} | ||
org.opencontainers.image.authors=Stijn Vermeeren <[email protected]> | ||
tags: | | ||
type=semver,pattern=v{{version}} | ||
- name: Log in to the GitHub container registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Build and push Docker image (api) | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: ./ | ||
push: true | ||
build-args: | | ||
VERSION=${{ env.VERSION }} | ||
tags: ${{ steps.meta-api.outputs.tags }} | ||
labels: ${{ steps.meta-api.outputs.labels }} | ||
cache-from: type=registry,ref=${{ env.BASE_IMAGE_NAME }}-api:edge | ||
cache-to: type=inline | ||
|
||
patch-changelog: | ||
runs-on: ubuntu-latest | ||
name: Patch CHANGELOG.md and update GitHub release notes | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set environment variables | ||
run: | | ||
echo GIT_BRANCH_NAME=mark-version-${TAG_NAME#v}-as-released >> $GITHUB_ENV | ||
echo GIT_COMMIT_MESSAGE=Mark version ${TAG_NAME#v} as released >> $GITHUB_ENV | ||
echo RELEASE_ID=$(gh api -H "Accept: application/vnd.github+json" /repos/${GITHUB_REPOSITORY}/releases/tags/${TAG_NAME} | jq '.id') >> $GITHUB_ENV | ||
- name: Get changelog for this specific release and update release notes | ||
run: | | ||
gh api \ | ||
--method PATCH \ | ||
--header "Accept: application/vnd.github+json" \ | ||
/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID} \ | ||
-f body="$(./get-changelog.sh)" | ||
- name: Checkout new branch and patch changelog | ||
run: | | ||
git checkout -b $GIT_BRANCH_NAME | ||
sed -i "/^\#\# \[Unreleased\]$/a \\\n\#\# $TAG_NAME - $(date '+%Y-%m-%d')" CHANGELOG.md | ||
- name: Commit, push and create pull request | ||
run: | | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "Github build action" | ||
git commit -am "$GIT_COMMIT_MESSAGE" | ||
git push --set-upstream origin $GIT_BRANCH_NAME | ||
gh pr create --title "$GIT_COMMIT_MESSAGE" --body "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Changelog | ||
|
||
## [Unreleased] | ||
|
||
### Changed | ||
|
||
|
||
### Fixed | ||
|
||
|
||
## v1.0.0 - 2024-10-07 | ||
|
||
### Added | ||
|
||
- Initial Version of the API | ||
|
||
### Changed | ||
|
||
|
||
### Fixed | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1.0 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/bash | ||
# This script gets all changelog entries from CHANGELOG.md since last release. | ||
|
||
set -e | ||
|
||
tempDir="$(mktemp -d)" | ||
tempFile=$tempDir/gh_release_notes.md | ||
|
||
# Get changelog entries since last release | ||
cat CHANGELOG.md | \ | ||
grep -Pazo '(?s)(?<=\#{2} \[Unreleased\]\n{2}).*?(?=\n\#{2} v|$)' \ | ||
> $tempFile | ||
|
||
# Improve readability and add some icons | ||
sed -i -E 's/(###) (Added)/\1 🚀 \2/' $tempFile | ||
sed -i -E 's/(###) (Changed)/\1 🔨 \2/' $tempFile | ||
sed -i -E 's/(###) (Fixed)/\1 🐛 \2/' $tempFile | ||
sed -i 's/\x0//g' $tempFile | ||
|
||
cat $tempFile | ||
|
||
# Cleanup temporary files | ||
trap 'rm -rf -- "$tempDir"' EXIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
eab241f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage Report