-
-
Notifications
You must be signed in to change notification settings - Fork 0
212 lines (185 loc) · 7.78 KB
/
auto-update-glpi.yml
File metadata and controls
212 lines (185 loc) · 7.78 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
name: Auto GLPI Update and Docker Image CI
on:
schedule:
# Runs at 03:00 UTC every Monday
- cron: "0 3 * * 1"
workflow_dispatch: # Allows manual triggering
inputs:
force_rebuild:
description: 'Force Docker Image Rebuild (even if version matches)'
required: false
default: false
type: boolean
# Keep push/tag triggers for manual/external triggers
push:
branches:
- 'main'
tags:
- "*.*.*"
paths-ignore:
- 'README.md'
- 'LICENSE'
- 'README_FR.md'
permissions:
contents: write # To commit changes, create tags, and create releases
jobs:
check-update-commit:
runs-on: ubuntu-latest
outputs:
update_needed: ${{ steps.version_check.outputs.update_needed }}
new_version: ${{ steps.latest_glpi_release.outputs.version }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get current version from Dockerfile
id: current_version_dockerfile
run: |
# Extract version (handles quotes, spaces, or malformed lines)
CURRENT_VERSION_IN_FILE=$(sed -nE 's/.*VERSION_GLPI[ ="\t]+([0-9]+\.[0-9]+\.[0-9]+).*/\1/p' Dockerfile | head -n 1)
if [ -z "$CURRENT_VERSION_IN_FILE" ]; then
echo "Warning: Could not extract current version from Dockerfile."
echo "version=null" >> $GITHUB_OUTPUT
else
echo "Current version in Dockerfile: $CURRENT_VERSION_IN_FILE"
echo "version=$CURRENT_VERSION_IN_FILE" >> $GITHUB_OUTPUT
fi
- name: Get latest GLPI release version
id: latest_glpi_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Fetch releases, filter, sort by version, take top one
NEW_GLPI_VERSION=$(curl -sL \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
"https://api.github.com/repos/glpi-project/glpi/releases" \
| jq -r '.[] | select(.prerelease==false and .draft==false) | .tag_name' \
| sort -V \
| tail -n 1)
echo "Latest GLPI version from upstream: $NEW_GLPI_VERSION"
if [ -z "$NEW_GLPI_VERSION" ] || [ "$NEW_GLPI_VERSION" == "null" ]; then
echo "Error: Could not fetch valid version from upstream. Aborting."
exit 1
fi
echo "version=$NEW_GLPI_VERSION" >> $GITHUB_OUTPUT
- name: Compare versions
id: version_check
run: |
CURRENT_VER="${{ steps.current_version_dockerfile.outputs.version }}"
LATEST_UPSTREAM_VER="${{ steps.latest_glpi_release.outputs.version }}"
echo "Comparing Current: $CURRENT_VER vs Upstream: $LATEST_UPSTREAM_VER"
# If current is null, we MUST update to fix the build
if [ "$CURRENT_VER" == "null" ]; then
echo "Current version is unknown/null. Forcing update."
echo "update_needed=true" >> $GITHUB_OUTPUT
exit 0
fi
if dpkg --compare-versions "$LATEST_UPSTREAM_VER" gt "$CURRENT_VER"; then
echo "New GLPI version available."
echo "update_needed=true" >> $GITHUB_OUTPUT
else
echo "Current version is up-to-date."
echo "update_needed=false" >> $GITHUB_OUTPUT
fi
- name: Update files if new version is available
if: steps.version_check.outputs.update_needed == 'true'
run: |
NEW_VER="${{ steps.latest_glpi_release.outputs.version }}"
echo "Forcing update to version: $NEW_VER"
# Aggressive replacements (fix "null" or mismatching formats)
sed -i "s/^ENV VERSION_GLPI.*/ENV VERSION_GLPI=\"${NEW_VER}\"/" Dockerfile
sed -i "s|image: triatk/glpi-standalone:.*|image: triatk/glpi-standalone:${NEW_VER}|g" docker-compose.yml
sed -i "s|- VERSION_GLPI=.*|- VERSION_GLPI=${NEW_VER}|g" docker-compose.yml
sed -i "s/:=.*}/:=${NEW_VER}}/" glpi-start.sh
CURRENT_VER="${{ steps.current_version_dockerfile.outputs.version }}"
if [ "$CURRENT_VER" != "null" ]; then
sed -i "s|${CURRENT_VER}|${NEW_VER}|g" README.md README_FR.md || true
fi
- name: Commit and push changes
if: steps.version_check.outputs.update_needed == 'true'
run: |
NEW_VER="${{ steps.latest_glpi_release.outputs.version }}"
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
if git diff --exit-code; then
echo "No changes detected. Skipping commit."
else
git add Dockerfile docker-compose.yml glpi-start.sh README.md README_FR.md
git commit -m "Bump GLPI to ${NEW_VER} (Automated)"
git push origin HEAD
fi
- name: Create Git tag
if: steps.version_check.outputs.update_needed == 'true'
run: |
NEW_VER="${{ steps.latest_glpi_release.outputs.version }}"
# Only tag if tag doesn't exist
if git rev-parse "$NEW_VER" >/dev/null 2>&1; then
echo "Tag $NEW_VER already exists. Skipping."
else
git tag "$NEW_VER" -m "Release GLPI Standalone ${NEW_VER}"
git push origin "$NEW_VER"
fi
- name: Create GitHub Release
if: steps.version_check.outputs.update_needed == 'true'
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.latest_glpi_release.outputs.version }}
name: GLPI Standalone ${{ steps.latest_glpi_release.outputs.version }}
body: "Automated release. Upstream: https://github.com/glpi-project/glpi/releases/tag/${{ steps.latest_glpi_release.outputs.version }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
docker:
runs-on: ubuntu-latest
needs: check-update-commit
# Run if:
# 1. Manual push/tag
# 2. Update was needed (new version found)
# 3. Force rebuild was selected manually
if: |
(github.event_name == 'push' || github.event_name == 'create') ||
(needs.check-update-commit.outputs.update_needed == 'true') ||
(inputs.force_rebuild == true)
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Docker meta
id: meta_glpi-standalone
uses: docker/metadata-action@v5
with:
images: |
triatk/glpi-standalone
flavor: |
latest=true
tags: |
# Use the upstream version calculated in the previous job if this is an automated update OR a forced rebuild
type=raw,value=${{ needs.check-update-commit.outputs.new_version }}
# Standard tags
type=schedule
type=ref,event=branch
type=ref,event=pr
type=pep440,pattern={{version}}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: Build and push
id: docker_build
uses: docker/build-push-action@v6
with:
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta_glpi-standalone.outputs.tags }}
labels: ${{ steps.meta_glpi-standalone.outputs.labels }}