-
Notifications
You must be signed in to change notification settings - Fork 7
145 lines (117 loc) · 5.28 KB
/
maven-cd.yml
File metadata and controls
145 lines (117 loc) · 5.28 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# Deploying Java with Maven to GitHub Container Registry
# https://docs.github.com/en/actions/use-cases-and-examples/publishing-packages/publishing-docker-images
name: Java CD
on:
push:
tags:
- "v*.*.*-*"
env:
JAVA_VERSION: 25
jobs:
test:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Set up OpenJDK ${{ env.JAVA_VERSION }}
uses: actions/setup-java@v5.2.0
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: "temurin"
cache: "maven"
- name: Compile and verify with Maven
run: ./mvnw clean verify
release:
needs: test
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Extract and validate tag components
id: tag
run: |
TAG="${GITHUB_REF#refs/tags/}"
echo "Full tag: $TAG"
SEMVER=$(echo "$TAG" | sed -E 's/^v([0-9]+\.[0-9]+\.[0-9]+)-.+$/\1/')
CLUB=$(echo "$TAG" | sed -E 's/^v[0-9]+\.[0-9]+\.[0-9]+-(.+)$/\1/')
VALID_CLUBS="arsenal barcelona chelsea dortmund everton flamengo galatasaray hamburg inter juventus kaiserslautern liverpool manchesterutd napoli olympique psg qpr realmadrid sevilla tottenham union valencia werder xerez youngboys zenit"
if ! echo "$SEMVER" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "❌ Invalid semver: $SEMVER"
exit 1
fi
if ! echo "$VALID_CLUBS" | grep -qw "$CLUB"; then
echo "❌ Invalid club name: $CLUB"
echo "Valid clubs: $VALID_CLUBS"
exit 1
fi
echo "semver=$SEMVER" >> "$GITHUB_OUTPUT"
echo "club=$CLUB" >> "$GITHUB_OUTPUT"
echo "✅ Tag: v$SEMVER - $CLUB"
- name: Log in to GitHub Container Registry
uses: docker/login-action@v4.1.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4.0.0
- name: Set image name
id: image
run: echo "name=$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT"
- name: Build and push Docker image to GitHub Container Registry
uses: docker/build-push-action@v7.0.0
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
provenance: false
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
ghcr.io/${{ steps.image.outputs.name }}:latest
ghcr.io/${{ steps.image.outputs.name }}:${{ steps.tag.outputs.semver }}
ghcr.io/${{ steps.image.outputs.name }}:${{ steps.tag.outputs.club }}
- name: Generate changelog
id: changelog
run: |
CURRENT_TAG="${GITHUB_REF#refs/tags/}"
PREVIOUS_TAG=$(git tag --sort=-version:refname | grep -Fxv "$CURRENT_TAG" | head -n 1)
if [ -n "$PREVIOUS_TAG" ]; then
CHANGELOG=$(git log "$PREVIOUS_TAG"..HEAD --pretty=format:"- %s" --no-merges)
else
CHANGELOG=$(git log --pretty=format:"- %s" --no-merges)
fi
{
echo "content<<EOF"
echo "$CHANGELOG"
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Create GitHub Release
uses: softprops/action-gh-release@v2.6.1
with:
name: "v${{ steps.tag.outputs.semver }} - ${{ steps.tag.outputs.club }} 🏆"
body: |
## What's Changed
${{ steps.changelog.outputs.content }}
## Docker
```bash
# By semantic version (recommended)
docker pull ghcr.io/${{ steps.image.outputs.name }}:${{ steps.tag.outputs.semver }}
# By club name
docker pull ghcr.io/${{ steps.image.outputs.name }}:${{ steps.tag.outputs.club }}
# Latest
docker pull ghcr.io/${{ steps.image.outputs.name }}:latest
```
## Quick Start
```bash
docker run -p 9000:9000 ghcr.io/${{ steps.image.outputs.name }}:${{ steps.tag.outputs.semver }}
```
API available at `http://localhost:9000` · Swagger UI at `http://localhost:9000/swagger/index.html`
generate_release_notes: false