|
| 1 | +name: Release Badge |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published, edited, prereleased] |
| 6 | + push: |
| 7 | + tags: |
| 8 | + - 'v*' |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: write |
| 13 | + pull-requests: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + make-badge: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Check out main (read-only; PR will target this) |
| 21 | + uses: actions/checkout@v4 |
| 22 | + with: |
| 23 | + ref: ${{ github.event.repository.default_branch }} |
| 24 | + fetch-depth: 0 |
| 25 | + |
| 26 | + - name: Determine version and label |
| 27 | + id: meta |
| 28 | + shell: bash |
| 29 | + run: | |
| 30 | + set -e |
| 31 | + if [ "${{ github.event_name }}" = "release" ]; then |
| 32 | + VERSION="${{ github.event.release.tag_name }}" |
| 33 | + if [ "${{ github.event.release.prerelease }}" = "true" ]; then |
| 34 | + LABEL="prerelease" |
| 35 | + else |
| 36 | + LABEL="release" |
| 37 | + fi |
| 38 | + else |
| 39 | + git fetch --tags --force --prune |
| 40 | + VERSION="$(git describe --tags --abbrev=0 2>/dev/null || echo 'v0.0.0')" |
| 41 | + LABEL="release" |
| 42 | + fi |
| 43 | +
|
| 44 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 45 | + echo "label=$LABEL" >> $GITHUB_OUTPUT |
| 46 | +
|
| 47 | + - name: Generate SVG badge |
| 48 | + shell: bash |
| 49 | + run: | |
| 50 | + set -e |
| 51 | + mkdir -p Documentation/Images |
| 52 | +
|
| 53 | + LABEL='${{ steps.meta.outputs.label }}' |
| 54 | + VERSION='${{ steps.meta.outputs.version }}' |
| 55 | +
|
| 56 | + # Calculate widths for a Shields-like look |
| 57 | + label_chars=${#LABEL} |
| 58 | + vers_chars=${#VERSION} |
| 59 | + label_w=$(( label_chars * 6 + 20 )) |
| 60 | + right_w=$(( vers_chars * 8 + 20 )) |
| 61 | + [ $label_w -lt 60 ] && label_w=60 |
| 62 | + [ $right_w -lt 80 ] && right_w=80 |
| 63 | + total_w=$(( label_w + right_w )) |
| 64 | + lx=$(( label_w / 2 )) |
| 65 | + rx=$(( label_w + right_w / 2 )) |
| 66 | +
|
| 67 | + cat > Documentation/Images/release.svg <<EOF |
| 68 | + <svg xmlns="http://www.w3.org/2000/svg" width="${total_w}" height="20" role="img" aria-label="${LABEL}: ${VERSION}"> |
| 69 | + <linearGradient id="s" x2="0" y2="100%"> |
| 70 | + <stop offset="0" stop-color="#bbb" stop-opacity=".1"/> |
| 71 | + <stop offset="1" stop-opacity=".1"/> |
| 72 | + </linearGradient> |
| 73 | + <mask id="m"><rect width="${total_w}" height="20" rx="3" fill="#fff"/></mask> |
| 74 | + <g mask="url(#m)"> |
| 75 | + <rect width="${label_w}" height="20" fill="#555"/> |
| 76 | + <rect x="${label_w}" width="${right_w}" height="20" fill="#2ea44f"/> |
| 77 | + <rect width="${total_w}" height="20" fill="url(#s)"/> |
| 78 | + </g> |
| 79 | + <g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" font-size="11"> |
| 80 | + <text x="${lx}" y="14">${LABEL}</text> |
| 81 | + <text x="${rx}" y="14">${VERSION}</text> |
| 82 | + </g> |
| 83 | + </svg> |
| 84 | + EOF |
| 85 | +
|
| 86 | + - name: Open PR with badge update |
| 87 | + uses: peter-evans/create-pull-request@v6 |
| 88 | + with: |
| 89 | + commit-message: "chore: update release badge -> ${{ steps.meta.outputs.version }}" |
| 90 | + title: "chore: update release badge -> ${{ steps.meta.outputs.version }}" |
| 91 | + body: | |
| 92 | + Automated update of `Documentation/Images/release.svg` |
| 93 | + - **Label:** `${{ steps.meta.outputs.label }}` |
| 94 | + - **Version:** `${{ steps.meta.outputs.version }}` |
| 95 | + branch: "bot/release-badge/${{ steps.meta.outputs.version }}" |
| 96 | + base: ${{ github.event.repository.default_branch }} |
| 97 | + labels: automation, docs |
| 98 | + add-paths: | |
| 99 | + Documentation/Images/release.svg |
0 commit comments