Skip to content

Commit ee27be5

Browse files
committed
harden bump-version workflow
- validate dbt-package-version via env var, fail-closed on invalid input - flow validated version through env vars to all downstream run: steps - SHA-pin repo-sync/pull-request@v2 - deny GITHUB_TOKEN by default, grant minimum per job Made-with: Cursor
1 parent 04d8fde commit ee27be5

1 file changed

Lines changed: 29 additions & 21 deletions

File tree

.github/workflows/bump-version.yml

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,58 +13,66 @@ on:
1313
type: string
1414
required: true
1515

16+
permissions: {}
17+
1618
jobs:
1719
validate-version:
1820
runs-on: ubuntu-latest
21+
permissions: {}
1922
outputs:
20-
validated-dbt-package-version: ${{ steps.validate-dbt-package-input.outputs.dbt-package-validation }}
23+
version: ${{ steps.validate.outputs.version }}
2124
steps:
22-
- name: validate dbt package version
23-
id: validate-dbt-package-input
24-
run: echo "dbt-package-validation=$(echo ${{ inputs.dbt-package-version }} | sed -n '/^[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$/p')" >> $GITHUB_OUTPUT
25-
- name: echo versions
25+
- name: Validate dbt package version
26+
id: validate
27+
env:
28+
VERSION: ${{ inputs.dbt-package-version }}
2629
run: |
27-
echo "dbt package version: ${{ steps.validate-dbt-package-input.outputs.dbt-package-validation }}"
28-
- name: fail on invalid input
29-
if: ${{ steps.validate-dbt-package-input.outputs.dbt-package-validation == '' }}
30-
uses: actions/github-script@v8
31-
with:
32-
script: |
33-
core.setFailed("Invalid version input - ${{ inputs.dbt-package-version }}")
30+
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
31+
echo "::error::Invalid version: $VERSION"
32+
exit 1
33+
fi
34+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
3435
3536
bump-version:
3637
needs: validate-version
3738
runs-on: ubuntu-latest
39+
permissions:
40+
contents: write
41+
env:
42+
VERSION: ${{ needs.validate-version.outputs.version }}
3843
steps:
3944
- name: Checkout code
4045
uses: actions/checkout@v6
4146
- name: Create release branch
42-
run: git checkout -b release/${{ inputs.dbt-package-version }}
47+
run: git checkout -b "release/$VERSION"
4348
- name: Initial config
4449
run: |
4550
git config user.name "GitHub Actions"
4651
git config user.email noreply@github.com
4752
- name: Bump package version
4853
run: |
49-
sed -i 's/version: "[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*"$/version: "${{ inputs.dbt-package-version }}"/' ./dbt_project.yml
54+
sed -i 's/version: "[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*"$/version: "'"$VERSION"'"/' ./dbt_project.yml
5055
- name: Bump readme package version
5156
run: |
52-
sed -i 's/version: [0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$/version: ${{ inputs.dbt-package-version }}/' ./README.md
57+
sed -i 's/version: [0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$/version: '"$VERSION"'/' ./README.md
5358
- name: Commit changes
54-
run: git commit -am "release ${{ inputs.dbt-package-version }}"
59+
run: git commit -am "release $VERSION"
5560
- name: Push code
56-
run: git push origin release/${{ inputs.dbt-package-version }}
61+
run: git push origin "release/$VERSION"
5762

5863
create-pr:
59-
needs: bump-version
64+
needs: [validate-version, bump-version]
6065
runs-on: ubuntu-latest
66+
permissions:
67+
contents: read
68+
pull-requests: write
6169
steps:
6270
- uses: actions/checkout@v6
6371
- name: create pull request
64-
uses: repo-sync/pull-request@v2
72+
uses: repo-sync/pull-request@7e79a9f5dc3ad0ce53138f01df2fad14a04831c5 # v2
6573
with:
66-
source_branch: "release/${{ inputs.dbt-package-version }}"
74+
source_branch: "release/${{ needs.validate-version.outputs.version }}"
6775
destination_branch: "master"
68-
pr_title: "release/${{ inputs.dbt-package-version }}"
76+
pr_title: "release/${{ needs.validate-version.outputs.version }}"
6977
pr_body: "Open automatically using bump version workflow"
7078
github_token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)