-
Notifications
You must be signed in to change notification settings - Fork 4
73 lines (60 loc) · 2.01 KB
/
release.yaml
File metadata and controls
73 lines (60 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
name: Release with Docker image to GHCR
on:
push:
tags:
- 'v**'
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Verify tag points to a commit on main branch
id: verify_branch
run: |
TAG_COMMIT=$(git rev-list -n 1 $GITHUB_REF)
echo "Tag commit: $TAG_COMMIT"
# Fetch main branch commit
git fetch origin main
MAIN_COMMIT=$(git rev-parse origin/main)
echo "Main commit: $MAIN_COMMIT"
# Check if TAG_COMMIT is ancestor of main commit
if git merge-base --is-ancestor $TAG_COMMIT $MAIN_COMMIT; then
echo "continue=true" >> $GITHUB_OUTPUT
else
echo "continue=false" >> $GITHUB_OUTPUT
fi
- name: Stop if tag is not on main branch
if: steps.verify_branch.outputs.continue != 'true'
run: |
echo "Tag commit is not on main branch, skipping release."
exit 0
- name: lowercase repo
run: |
echo "REPO=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image to GHCR
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: |
ghcr.io/${{ env.REPO }}:${{ github.ref_name }}
ghcr.io/${{ env.REPO }}:latest
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
name: Release ${{ github.ref_name }}
body: |
Docker image pushed to GHCR:
```bash
docker pull ghcr.io/${{ env.REPO }}:${{ github.ref_name }}
```