-
Notifications
You must be signed in to change notification settings - Fork 0
111 lines (90 loc) · 2.99 KB
/
Copy pathrelease.yml
File metadata and controls
111 lines (90 loc) · 2.99 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
name: Release
on:
workflow_dispatch:
inputs:
version:
description: "New version, for example 0.1.1"
required: true
type: string
permissions:
contents: write
packages: write
jobs:
release:
name: Create release and publish Docker image
runs-on: ubuntu-latest
steps:
- name: Checkout main
uses: actions/checkout@v5
with:
ref: main
fetch-depth: 0
- name: Normalize and validate version
id: version
shell: bash
run: |
VERSION="${{ inputs.version }}"
VERSION="${VERSION#v}"
if ! echo "$VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "Invalid version: $VERSION"
echo "Use semantic versioning, for example: 0.1.1"
exit 1
fi
TAG="v$VERSION"
git fetch --tags
if git rev-parse "refs/tags/$TAG" >/dev/null 2>&1; then
echo "Tag $TAG already exists"
exit 1
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
- name: Update boot/version
shell: bash
run: |
echo "${{ steps.version.outputs.version }}" > boot/version
- name: Commit version change
shell: bash
run: |
git config user.name "github-actions"
git config user.email "github-actions@github.com"
git add boot/version
if git diff --cached --quiet; then
echo "boot/version already contains ${{ steps.version.outputs.version }}"
exit 1
fi
git commit -m "Release ${{ steps.version.outputs.tag }} [skip ci]"
git push origin main
- name: Create and push tag
shell: bash
run: |
git tag -a "${{ steps.version.outputs.tag }}" -m "Release ${{ steps.version.outputs.tag }}"
git push origin "${{ steps.version.outputs.tag }}"
- name: Create GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
gh release create "${{ steps.version.outputs.tag }}" \
--title "${{ steps.version.outputs.tag }}" \
--notes "Release ${{ steps.version.outputs.tag }}"
- name: Set Docker image name
id: image
shell: bash
run: |
echo "image=ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/tp2intervals" >> "$GITHUB_OUTPUT"
- name: Login to GHCR
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Build and push Docker image
uses: docker/build-push-action@v7
with:
context: .
push: true
tags: |
${{ steps.image.outputs.image }}:${{ steps.version.outputs.version }}
${{ steps.image.outputs.image }}:latest