fix(release): update badge on default branch
This commit is contained in:
parent
99abd59f05
commit
7a09dfe573
1 changed files with 16 additions and 8 deletions
24
.github/workflows/release.yml
vendored
24
.github/workflows/release.yml
vendored
|
|
@ -797,26 +797,34 @@ jobs:
|
||||||
|
|
||||||
- name: Update README version badge
|
- name: Update README version badge
|
||||||
if: ${{ inputs.publish_release }}
|
if: ${{ inputs.publish_release }}
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
DEFAULT_BRANCH="$(gh repo view "${GITHUB_REPOSITORY}" --json defaultBranchRef --jq '.defaultBranchRef.name')"
|
||||||
|
git fetch origin "${DEFAULT_BRANCH}"
|
||||||
|
BADGE_WORKTREE="$(mktemp -d)"
|
||||||
|
git worktree add --detach "${BADGE_WORKTREE}" "origin/${DEFAULT_BRANCH}"
|
||||||
|
trap 'git worktree remove --force "${BADGE_WORKTREE}" >/dev/null 2>&1 || true' EXIT
|
||||||
|
|
||||||
BADGE_LABEL_WIDTH=51
|
BADGE_LABEL_WIDTH=51
|
||||||
BADGE_VALUE="${RELEASE_TAG}"
|
BADGE_VALUE="${RELEASE_TAG}"
|
||||||
BADGE_VALUE_WIDTH=$(( ${#BADGE_VALUE} * 7 + 10 ))
|
BADGE_VALUE_WIDTH=$(( ${#BADGE_VALUE} * 7 + 10 ))
|
||||||
BADGE_WIDTH=$(( BADGE_LABEL_WIDTH + BADGE_VALUE_WIDTH ))
|
BADGE_WIDTH=$(( BADGE_LABEL_WIDTH + BADGE_VALUE_WIDTH ))
|
||||||
BADGE_LABEL_X=$(( BADGE_LABEL_WIDTH / 2 ))
|
BADGE_LABEL_X=$(( BADGE_LABEL_WIDTH / 2 ))
|
||||||
BADGE_VALUE_X=$(( BADGE_LABEL_WIDTH + BADGE_VALUE_WIDTH / 2 ))
|
BADGE_VALUE_X=$(( BADGE_LABEL_WIDTH + BADGE_VALUE_WIDTH / 2 ))
|
||||||
mkdir -p .github/badges
|
mkdir -p "${BADGE_WORKTREE}/.github/badges"
|
||||||
cat > .github/badges/version.svg <<EOF
|
cat > "${BADGE_WORKTREE}/.github/badges/version.svg" <<EOF
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="${BADGE_WIDTH}" height="20" role="img" aria-label="version: ${BADGE_VALUE}"><title>version: ${BADGE_VALUE}</title><g shape-rendering="crispEdges"><rect width="${BADGE_LABEL_WIDTH}" height="20" fill="#555"/><rect x="${BADGE_LABEL_WIDTH}" width="${BADGE_VALUE_WIDTH}" height="20" fill="#007ec6"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" font-size="11"><text x="${BADGE_LABEL_X}" y="14">version</text><text x="${BADGE_VALUE_X}" y="14">${BADGE_VALUE}</text></g></svg>
|
<svg xmlns="http://www.w3.org/2000/svg" width="${BADGE_WIDTH}" height="20" role="img" aria-label="version: ${BADGE_VALUE}"><title>version: ${BADGE_VALUE}</title><g shape-rendering="crispEdges"><rect width="${BADGE_LABEL_WIDTH}" height="20" fill="#555"/><rect x="${BADGE_LABEL_WIDTH}" width="${BADGE_VALUE_WIDTH}" height="20" fill="#007ec6"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" font-size="11"><text x="${BADGE_LABEL_X}" y="14">version</text><text x="${BADGE_VALUE_X}" y="14">${BADGE_VALUE}</text></g></svg>
|
||||||
EOF
|
EOF
|
||||||
if git diff --quiet -- .github/badges/version.svg; then
|
if git -C "${BADGE_WORKTREE}" diff --quiet -- .github/badges/version.svg; then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
git config user.name "github-actions[bot]"
|
git -C "${BADGE_WORKTREE}" config user.name "github-actions[bot]"
|
||||||
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
git -C "${BADGE_WORKTREE}" config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
||||||
git add .github/badges/version.svg
|
git -C "${BADGE_WORKTREE}" add .github/badges/version.svg
|
||||||
git commit -m "docs(readme): update release badge to ${BADGE_VALUE}"
|
git -C "${BADGE_WORKTREE}" commit -m "docs(readme): update release badge to ${BADGE_VALUE}"
|
||||||
git push
|
git -C "${BADGE_WORKTREE}" push origin "HEAD:${DEFAULT_BRANCH}"
|
||||||
|
|
||||||
- name: Keep release as draft
|
- name: Keep release as draft
|
||||||
if: ${{ github.event_name == 'workflow_dispatch' && !inputs.publish_release }}
|
if: ${{ github.event_name == 'workflow_dispatch' && !inputs.publish_release }}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue