|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + version: |
| 13 | + name: Determine version |
| 14 | + runs-on: ubuntu-latest |
| 15 | + outputs: |
| 16 | + new_tag: ${{ steps.tag.outputs.new_tag }} |
| 17 | + new_version: ${{ steps.tag.outputs.new_version }} |
| 18 | + changelog: ${{ steps.tag.outputs.changelog }} |
| 19 | + previous_tag: ${{ steps.tag.outputs.previous_tag }} |
| 20 | + steps: |
| 21 | + - name: Checkout |
| 22 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 23 | + with: |
| 24 | + fetch-depth: 0 |
| 25 | + |
| 26 | + - name: Determine next version |
| 27 | + id: tag |
| 28 | + uses: mathieudutour/github-tag-action@d28fa2ccfbd16e871a4bdf35e11b3ad1bd56c0c1 # v6.2 |
| 29 | + with: |
| 30 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 31 | + default_bump: patch |
| 32 | + tag_prefix: v |
| 33 | + |
| 34 | + bump: |
| 35 | + name: Bump version in files |
| 36 | + runs-on: ubuntu-latest |
| 37 | + needs: version |
| 38 | + if: needs.version.outputs.new_tag != '' |
| 39 | + steps: |
| 40 | + - name: Checkout |
| 41 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 42 | + with: |
| 43 | + ref: main |
| 44 | + |
| 45 | + - name: Bump versions from .version-bump.json |
| 46 | + env: |
| 47 | + NEW_VERSION: ${{ needs.version.outputs.new_version }} |
| 48 | + run: | |
| 49 | + echo "Bumping version to ${NEW_VERSION}" |
| 50 | +
|
| 51 | + jq -c '.files[]' .version-bump.json | while IFS= read -r entry; do |
| 52 | + FILE=$(echo "$entry" | jq -r '.path') |
| 53 | + FIELD=$(echo "$entry" | jq -r '.field') |
| 54 | +
|
| 55 | + if [ ! -f "$FILE" ]; then |
| 56 | + echo "::warning::File not found: $FILE" |
| 57 | + continue |
| 58 | + fi |
| 59 | +
|
| 60 | + # Convert dot-notation path to jq setpath array |
| 61 | + # e.g. "plugins.0.version" -> ["plugins",0,"version"] |
| 62 | + JQ_PATH=$(echo "$FIELD" | jq -R 'split(".") | map(if test("^[0-9]+$") then tonumber else . end)') |
| 63 | +
|
| 64 | + echo "Updating $FILE field '$FIELD' to $NEW_VERSION" |
| 65 | + jq --arg v "$NEW_VERSION" --argjson path "$JQ_PATH" 'setpath($path; $v)' "$FILE" > tmp.$$.json && mv tmp.$$.json "$FILE" |
| 66 | + done |
| 67 | +
|
| 68 | + - name: Audit for stale version references |
| 69 | + env: |
| 70 | + PREVIOUS_TAG: ${{ needs.version.outputs.previous_tag }} |
| 71 | + run: | |
| 72 | + PREVIOUS_VERSION="${PREVIOUS_TAG#v}" |
| 73 | +
|
| 74 | + if [ -z "$PREVIOUS_VERSION" ]; then |
| 75 | + echo "No previous version to audit against" |
| 76 | + exit 0 |
| 77 | + fi |
| 78 | +
|
| 79 | + echo "Auditing for stale references to ${PREVIOUS_VERSION}" |
| 80 | +
|
| 81 | + EXCLUDE_ARGS="" |
| 82 | + for pattern in $(jq -r '.audit.exclude[]' .version-bump.json); do |
| 83 | + EXCLUDE_ARGS="$EXCLUDE_ARGS --exclude=$pattern --exclude-dir=$pattern" |
| 84 | + done |
| 85 | +
|
| 86 | + if grep -r "$PREVIOUS_VERSION" . $EXCLUDE_ARGS --include='*.json' --include='*.md' --include='*.yml' --include='*.yaml' 2>/dev/null; then |
| 87 | + echo "::warning::Found stale version references to ${PREVIOUS_VERSION} — check the files above" |
| 88 | + else |
| 89 | + echo "No stale version references found" |
| 90 | + fi |
| 91 | +
|
| 92 | + - name: Commit and push version bump |
| 93 | + uses: stefanzweifel/git-auto-commit-action@04702edda442b2e678b25b537cec683a1493fcb9 # v7.1.0 |
| 94 | + with: |
| 95 | + commit_message: "chore(release): bump version to v${{ needs.version.outputs.new_version }}" |
| 96 | + file_pattern: "*.json **/*.json" |
| 97 | + |
| 98 | + release: |
| 99 | + name: Create GitHub release |
| 100 | + runs-on: ubuntu-latest |
| 101 | + needs: [version, bump] |
| 102 | + steps: |
| 103 | + - name: Create release |
| 104 | + uses: actions/github-script@d746ffe35508b1917358783b479e04febd2b8f71 # v9.0.0 |
| 105 | + env: |
| 106 | + NEW_TAG: ${{ needs.version.outputs.new_tag }} |
| 107 | + CHANGELOG: ${{ needs.version.outputs.changelog }} |
| 108 | + with: |
| 109 | + script: | |
| 110 | + await github.rest.repos.createRelease({ |
| 111 | + owner: context.repo.owner, |
| 112 | + repo: context.repo.repo, |
| 113 | + tag_name: process.env.NEW_TAG, |
| 114 | + name: process.env.NEW_TAG, |
| 115 | + body: process.env.CHANGELOG, |
| 116 | + draft: false, |
| 117 | + prerelease: false |
| 118 | + }); |
0 commit comments