From c2bbc4dac5b625ffaeefed1db9e9d4f839816545 Mon Sep 17 00:00:00 2001 From: Shadoweee77 Date: Thu, 19 Feb 2026 23:41:55 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20cicd:=20Automate=20proper=20version?= =?UTF-8?q?=20tagging=20in=20the=20bouncer.go=20that=20is=20reported=20to?= =?UTF-8?q?=20Crowdsec=20LAPI=20(#314)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 * :bento: Simplify for tests Removed the verification step after updating the version and modified the commit message to include an emoji. --------- Co-authored-by: maxlerebourg --- .github/workflows/release.yml | 46 +++++++++++++++++++++++++++++++++++ bouncer.go | 4 +-- version.go | 4 +++ 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 version.go diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..5cf82a2 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,46 @@ +name: Release Version Update + +on: + release: + types: [published] + +permissions: + contents: write + +jobs: + update-version: + name: Update version in source + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v6 + with: + ref: main + + - name: Extract version from tag + id: get_version + run: | + TAG="${{ github.event.release.tag_name }}" + VERSION="${TAG#v}" + echo "version=$VERSION" >> "$GITHUB_OUTPUT" + echo "tag=$TAG" >> "$GITHUB_OUTPUT" + + - name: Update version in version.go + run: | + sed -i 's/pluginVersion = "[^"]*"/pluginVersion = "'"${{ steps.get_version.outputs.version }}"'"/' version.go + cat version.go + + - name: Commit, push, and retag + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add version.go + if git diff --cached --quiet; then + echo "Version already up to date, nothing to commit" + exit 0 + fi + git commit -m "⬆️ chore: bump version to ${{ steps.get_version.outputs.version }}" + git push origin main + # Move the release tag to include the version update + git tag -f "${{ steps.get_version.outputs.tag }}" + git push -f origin "${{ steps.get_version.outputs.tag }}" diff --git a/bouncer.go b/bouncer.go index 3e0bc0c..f2ab596 100644 --- a/bouncer.go +++ b/bouncer.go @@ -674,7 +674,7 @@ func crowdsecQuery(bouncer *Bouncer, stringURL string, data []byte) ([]byte, err req, _ = http.NewRequest(http.MethodGet, stringURL, nil) } req.Header.Add(bouncer.crowdsecHeader, bouncer.crowdsecKey) - req.Header.Add("User-Agent", "Crowdsec-Bouncer-Traefik-Plugin/1.X.X") + req.Header.Add("User-Agent", "Crowdsec-Bouncer-Traefik-Plugin/"+pluginVersion) res, err := bouncer.httpClient.Do(req) if err != nil { @@ -779,7 +779,7 @@ func reportMetrics(bouncer *Bouncer) error { metrics := map[string]interface{}{ "remediation_components": []map[string]interface{}{ { - "version": "1.X.X", + "version": pluginVersion, "type": "bouncer", "name": "traefik_plugin", "metrics": []map[string]interface{}{ diff --git a/version.go b/version.go new file mode 100644 index 0000000..962d243 --- /dev/null +++ b/version.go @@ -0,0 +1,4 @@ +package crowdsec_bouncer_traefik_plugin //nolint:revive,stylecheck + +// pluginVersion is updated automatically by the release workflow. +var pluginVersion = "1.5.0" //nolint:gochecknoglobals