Skip to content

Commit c2bbc4d

Browse files
✨ cicd: Automate proper version tagging in the bouncer.go that is reported to Crowdsec LAPI (#314)
* cicd(versioning): Automate proper version tagging in the bouncer.go that is reported to Crowdsec LAPI * cicd(versioning): Move pluginVersion to it's own file * Disablie lint check for no global variables * Remove trailing new-line * Update pluginVersion declaration style * 🍱 Simplify for tests Removed the verification step after updating the version and modified the commit message to include an emoji. --------- Co-authored-by: maxlerebourg <maxlerebourg@gmail.com>
1 parent 889c5b5 commit c2bbc4d

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

.github/workflows/release.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Release Version Update
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
permissions:
8+
contents: write
9+
10+
jobs:
11+
update-version:
12+
name: Update version in source
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v6
17+
with:
18+
ref: main
19+
20+
- name: Extract version from tag
21+
id: get_version
22+
run: |
23+
TAG="${{ github.event.release.tag_name }}"
24+
VERSION="${TAG#v}"
25+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
26+
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
27+
28+
- name: Update version in version.go
29+
run: |
30+
sed -i 's/pluginVersion = "[^"]*"/pluginVersion = "'"${{ steps.get_version.outputs.version }}"'"/' version.go
31+
cat version.go
32+
33+
- name: Commit, push, and retag
34+
run: |
35+
git config user.name "github-actions[bot]"
36+
git config user.email "github-actions[bot]@users.noreply.github.com"
37+
git add version.go
38+
if git diff --cached --quiet; then
39+
echo "Version already up to date, nothing to commit"
40+
exit 0
41+
fi
42+
git commit -m "⬆️ chore: bump version to ${{ steps.get_version.outputs.version }}"
43+
git push origin main
44+
# Move the release tag to include the version update
45+
git tag -f "${{ steps.get_version.outputs.tag }}"
46+
git push -f origin "${{ steps.get_version.outputs.tag }}"

bouncer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ func crowdsecQuery(bouncer *Bouncer, stringURL string, data []byte) ([]byte, err
674674
req, _ = http.NewRequest(http.MethodGet, stringURL, nil)
675675
}
676676
req.Header.Add(bouncer.crowdsecHeader, bouncer.crowdsecKey)
677-
req.Header.Add("User-Agent", "Crowdsec-Bouncer-Traefik-Plugin/1.X.X")
677+
req.Header.Add("User-Agent", "Crowdsec-Bouncer-Traefik-Plugin/"+pluginVersion)
678678

679679
res, err := bouncer.httpClient.Do(req)
680680
if err != nil {
@@ -779,7 +779,7 @@ func reportMetrics(bouncer *Bouncer) error {
779779
metrics := map[string]interface{}{
780780
"remediation_components": []map[string]interface{}{
781781
{
782-
"version": "1.X.X",
782+
"version": pluginVersion,
783783
"type": "bouncer",
784784
"name": "traefik_plugin",
785785
"metrics": []map[string]interface{}{

version.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package crowdsec_bouncer_traefik_plugin //nolint:revive,stylecheck
2+
3+
// pluginVersion is updated automatically by the release workflow.
4+
var pluginVersion = "1.5.0" //nolint:gochecknoglobals

0 commit comments

Comments
 (0)