Skip to content

Commit 7a68f4c

Browse files
committed
feat: added github actions auto push image to ghcr.io
1 parent 919b782 commit 7a68f4c

File tree

2 files changed

+138
-0
lines changed

2 files changed

+138
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Build and Publish Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
tags:
9+
- 'v*'
10+
pull_request:
11+
branches:
12+
- main
13+
- master
14+
15+
env:
16+
REGISTRY: ghcr.io
17+
IMAGE_NAME: ${{ github.repository }}
18+
19+
jobs:
20+
build-and-push:
21+
runs-on: ubuntu-latest
22+
permissions:
23+
contents: read
24+
packages: write
25+
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@v4
29+
30+
- name: Set up Docker Buildx
31+
uses: docker/setup-buildx-action@v3
32+
33+
- name: Log in to the Container registry
34+
uses: docker/login-action@v3
35+
with:
36+
registry: ${{ env.REGISTRY }}
37+
username: ${{ github.actor }}
38+
password: ${{ secrets.GITHUB_TOKEN }}
39+
40+
- name: Extract metadata
41+
id: meta
42+
uses: docker/metadata-action@v5
43+
with:
44+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
45+
tags: |
46+
type=ref,event=branch
47+
type=ref,event=pr
48+
type=semver,pattern={{version}}
49+
type=semver,pattern={{major}}.{{minor}}
50+
type=semver,pattern={{major}}
51+
type=sha,prefix={{branch}}-
52+
type=raw,value=latest,enable={{is_default_branch}}
53+
54+
- name: Build and push Docker image
55+
uses: docker/build-push-action@v5
56+
with:
57+
context: .
58+
platforms: linux/amd64,linux/arm64
59+
push: true
60+
tags: ${{ steps.meta.outputs.tags }}
61+
labels: ${{ steps.meta.outputs.labels }}
62+
cache-from: type=gha
63+
cache-to: type=gha,mode=max

.github/workflows/release.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Create Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
create-release:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
packages: read
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Get the version
22+
id: get_version
23+
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
24+
25+
- name: Get previous tag
26+
id: prev_tag
27+
run: |
28+
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
29+
echo "PREV_TAG=${PREV_TAG}" >> $GITHUB_OUTPUT
30+
31+
- name: Generate changelog
32+
id: changelog
33+
run: |
34+
if [ -z "${{ steps.prev_tag.outputs.PREV_TAG }}" ]; then
35+
CHANGELOG=$(git log --pretty=format:"- %s (%h)" HEAD)
36+
else
37+
CHANGELOG=$(git log --pretty=format:"- %s (%h)" ${{ steps.prev_tag.outputs.PREV_TAG }}..HEAD)
38+
fi
39+
echo "CHANGELOG<<EOF" >> $GITHUB_OUTPUT
40+
echo "$CHANGELOG" >> $GITHUB_OUTPUT
41+
echo "EOF" >> $GITHUB_OUTPUT
42+
43+
- name: Wait for Docker build
44+
run: |
45+
echo "Waiting for Docker image to be built..."
46+
sleep 30
47+
48+
- name: Create Release
49+
uses: actions/create-release@v1
50+
env:
51+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52+
with:
53+
tag_name: ${{ steps.get_version.outputs.VERSION }}
54+
release_name: Release ${{ steps.get_version.outputs.VERSION }}
55+
body: |
56+
## Changes in this Release
57+
58+
${{ steps.changelog.outputs.CHANGELOG }}
59+
60+
## Docker Image
61+
62+
Pull the Docker image for this release:
63+
```bash
64+
docker pull ghcr.io/${{ github.repository }}:${{ steps.get_version.outputs.VERSION }}
65+
```
66+
67+
Or use the latest tag:
68+
```bash
69+
docker pull ghcr.io/${{ github.repository }}:latest
70+
```
71+
72+
## What's Changed
73+
**Full Changelog**: https://github.com/${{ github.repository }}/compare/${{ steps.prev_tag.outputs.PREV_TAG }}...${{ steps.get_version.outputs.VERSION }}
74+
draft: false
75+
prerelease: ${{ contains(steps.get_version.outputs.VERSION, '-rc') || contains(steps.get_version.outputs.VERSION, '-beta') || contains(steps.get_version.outputs.VERSION, '-alpha') }}

0 commit comments

Comments
 (0)