Skip to content

Commit 136f9ca

Browse files
committed
adding release workflow
1 parent a968c57 commit 136f9ca

File tree

2 files changed

+89
-33
lines changed

2 files changed

+89
-33
lines changed

.github/workflows/build_and_publish_docker.yaml

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build and Publish Docker Image
1+
name: Build and Push Docker Image
22

33
on:
44
release:
@@ -15,14 +15,14 @@ on:
1515
env:
1616
REGISTRY: ghcr.io
1717
IMAGE_NAME: ${{ github.repository }}
18-
IMAGE_NAME_LOWER: ${{ github.repository_owner }}/${{ github.event.repository.name }}
1918

2019
jobs:
2120
build-and-push:
2221
name: Build and Push Docker Image
2322
runs-on: ubuntu-latest
23+
2424
permissions:
25-
contents: write
25+
contents: read
2626
packages: write
2727

2828
steps:
@@ -32,52 +32,53 @@ jobs:
3232
- name: Set up Docker Buildx
3333
uses: docker/setup-buildx-action@v3
3434

35-
- name: Log in to GHCR
35+
- name: Log in to GitHub Container Registry
3636
uses: docker/login-action@v3
3737
with:
3838
registry: ${{ env.REGISTRY }}
3939
username: ${{ github.actor }}
4040
password: ${{ secrets.GITHUB_TOKEN }}
4141

42-
- name: Extract tag
43-
id: extract_tag
42+
- name: Extract tag name
43+
id: vars
4444
run: |
45-
VERSION_TAG=${GITHUB_REF##*/}
46-
echo "version=$VERSION_TAG" >> "$GITHUB_OUTPUT"
47-
echo "image=ghcr.io/${{ env.IMAGE_NAME_LOWER }}" >> "$GITHUB_OUTPUT"
45+
TAG_NAME=${GITHUB_REF#refs/tags/}
46+
IMAGE_NAME_LOWER=$(echo "${GITHUB_REPOSITORY}" | tr '[:upper:]' '[:lower:]')
47+
echo "tag=${TAG_NAME}" >> $GITHUB_OUTPUT
48+
echo "image_name=${IMAGE_NAME_LOWER}" >> $GITHUB_OUTPUT
49+
50+
if [[ "$TAG_NAME" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
51+
echo "latest=true" >> $GITHUB_OUTPUT
52+
else
53+
echo "latest=false" >> $GITHUB_OUTPUT
54+
fi
4855
49-
- name: Build and Push Docker image
56+
- name: Build and push Docker image
5057
uses: docker/build-push-action@v5
5158
with:
5259
context: .
53-
file: src/docker/Dockerfile
60+
file: ./src/docker/Dockerfile
5461
push: true
5562
tags: |
56-
${{ steps.extract_tag.outputs.image }}:${{ steps.extract_tag.outputs.version }}
57-
${{ steps.extract_tag.outputs.image }}:latest
63+
ghcr.io/${{ steps.vars.outputs.image_name }}:${{ steps.vars.outputs.tag }}
64+
${{ steps.vars.outputs.latest == 'true' && format('ghcr.io/{0}:latest', steps.vars.outputs.image_name) || '' }}
5865
labels: |
5966
org.opencontainers.image.source=${{ github.repositoryUrl }}
60-
org.opencontainers.image.version=${{ steps.extract_tag.outputs.version }}
67+
org.opencontainers.image.version=${{ steps.vars.outputs.tag }}
68+
org.opencontainers.image.created=${{ github.event.head_commit.timestamp || github.event.release.published_at || github.event.repository.updated_at }}
6169
org.opencontainers.image.revision=${{ github.sha }}
70+
org.opencontainers.image.title=${{ github.repository }}
6271
63-
- name: Generate Release Notes
64-
uses: softprops/action-gh-release@v2
72+
- name: Confirm tags pushed
73+
run: |
74+
echo "Published ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.vars.outputs.tag }}"
75+
if [ "${{ steps.vars.outputs.latest }}" = "true" ]; then
76+
echo "Also tagged as :latest"
77+
fi
78+
- name: Create GitHub Release
79+
if: startsWith(github.ref, 'refs/tags/') && steps.vars.outputs.latest == 'true'
80+
uses: softprops/action-gh-release@v1
6581
with:
66-
tag_name: ${{ steps.extract_tag.outputs.version }}
82+
tag_name: ${{ steps.vars.outputs.tag }}
83+
name: Release ${{ steps.vars.outputs.tag }}
6784
generate_release_notes: true
68-
env:
69-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
70-
71-
- name: Generate CHANGELOG.md
72-
uses: heinrichreimer/action-github-changelog-generator@v2.3
73-
with:
74-
token: ${{ secrets.GITHUB_TOKEN }}
75-
output: CHANGELOG.md
76-
tag: ${{ steps.extract_tag.outputs.version }}
77-
78-
- name: Commit updated CHANGELOG.md
79-
uses: stefanzweifel/git-auto-commit-action@v5
80-
with:
81-
commit_message: "chore: update CHANGELOG.md for ${{ steps.extract_tag.outputs.version }}"
82-
branch: main
83-
file_pattern: CHANGELOG.md

.github/workflows/release.yaml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Release and Changelog
2+
3+
on:
4+
release:
5+
types: [created]
6+
workflow_dispatch:
7+
push:
8+
tags:
9+
- '[0-9]+.[0-9]+.[0-9]+'
10+
11+
permissions:
12+
contents: write
13+
pull-requests: write
14+
15+
jobs:
16+
generate-release:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v4
22+
23+
- name: Set up Git
24+
run: |
25+
git config user.name "github-actions[bot]"
26+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
27+
28+
- name: Get latest release tag
29+
id: get_tag
30+
run: echo "tag=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT"
31+
32+
- name: Generate release notes
33+
id: notes
34+
uses: actions/github-script@v7
35+
with:
36+
script: |
37+
const { data: release } = await github.rest.repos.getReleaseByTag({
38+
owner: context.repo.owner,
39+
repo: context.repo.repo,
40+
tag: process.env.GITHUB_REF_NAME,
41+
});
42+
43+
const notes = release.body || 'No release notes provided.';
44+
return { notes };
45+
46+
- name: Append to CHANGELOG.md
47+
run: |
48+
echo "## ${{ steps.get_tag.outputs.tag }}" >> CHANGELOG.md
49+
echo "" >> CHANGELOG.md
50+
echo "${{ steps.notes.outputs.result.notes }}" >> CHANGELOG.md
51+
echo "" >> CHANGELOG.md
52+
git add CHANGELOG.md
53+
git commit -m "docs: update CHANGELOG for ${{ steps.get_tag.outputs.tag }}"
54+
git push origin HEAD
55+

0 commit comments

Comments
 (0)