-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(automate): automate version bump for pre-commit repo #12
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
b8ef75a
Do text subst
a17c837
take arg
7de67c4
Attempt at script1
1c95ea9
write second script
91348e2
Update scripts to branch + aproximation of what a workflow could look…
76e4641
Use right flag to checkout branch + change file name
1a3e71d
Commit via workflow not via script
b56adb4
fix workflow file
889a37e
change file name & remove dup
7a29ca1
Add v before version
d456a8c
No idea if this works
dc756c0
Don't commit
a2d5182
hello world
ccd1520
bogus
72cc2d1
Add work from other fork
478a0e2
consistant + remove useless checkout
01f5143
Restirct autoapprove to only semgrep-ci[bot]
0b9d98e
Make script less fragile?
6eb6af7
Split workflow into two
ef025e5
add conditonal
882a4d7
add back github actions bot
15aab20
spacing
9e3b0aa
actually call the right script
76c6ece
Add changes to tag-version
6640368
Update scripts/tag-version.sh
yosefAlsuhaibani 780eef4
Add shebang
3b9f235
Merge branch 'develop' into yosef/auto-version-bump
yosefAlsuhaibani b7192c5
Sync frm test fork. (#24)
yosefAlsuhaibani 547aa2a
Remove test files
d8e84e3
Only autoapprove via login == semgrep-ci[bot]
4351df5
Add comments
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# This workflow auto approves the PR generated by the bump_version | ||
# workflow, and moves the tag that was created in the PR's branch | ||
# to develop. | ||
|
||
name: github-actions auto-approve | ||
on: pull_request_target | ||
|
||
permissions: | ||
pull-requests: write | ||
contents: write | ||
|
||
jobs: | ||
approve-bot: | ||
runs-on: ubuntu-latest | ||
if: ${{ github.event.pull_request.user.login == 'semgrep-ci[bot]'}} | ||
steps: | ||
- name: Approve | ||
run: gh pr review --approve "$PR_URL" | ||
env: | ||
PR_URL: ${{ github.event.pull_request.html_url }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Watch untill PR checks are done | ||
run: gh pr checks --required --watch "$PR_URL" | ||
env: | ||
PR_URL: ${{ github.event.pull_request.html_url }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Merge PR | ||
run: gh pr merge --squash "$PR_URL" | ||
env: | ||
PR_URL: ${{ github.event.pull_request.html_url }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
# Now we switch to semgrep-ci[bot] to actually be able to | ||
# move the tag we created in bump_version.yml from the | ||
# release branch to develop | ||
|
||
- id: jwt | ||
env: | ||
EXPIRATION: 600 | ||
ISSUER: ${{ secrets.SEMGREP_CI_APP_ID }} | ||
PRIVATE_KEY: ${{ secrets.SEMGREP_CI_APP_KEY }} | ||
name: Get JWT for semgrep-ci GitHub App | ||
uses: docker://public.ecr.aws/y9k7q4m1/devops/cicd:latest | ||
|
||
- id: token | ||
name: Get token for semgrep-ci GitHub App | ||
run: | | ||
TOKEN="$(curl -X POST \ | ||
-H "Authorization: Bearer ${{ steps.jwt.outputs.jwt }}" \ | ||
-H "Accept: application/vnd.github.v3+json" \ | ||
"https://api.github.com/app/installations/${{ secrets.SEMGREP_CI_APP_INSTALLATION_ID }}/access_tokens" | \ | ||
jq -r .token)" | ||
echo "::add-mask::$TOKEN" | ||
echo "token=$TOKEN" >> $GITHUB_OUTPUT | ||
|
||
- uses: actions/checkout@v4 | ||
with: | ||
ref: develop | ||
token: ${{ steps.token.outputs.token }} | ||
|
||
- name: Move tag to develop branch | ||
env: | ||
GITHUB_TOKEN: ${{ steps.token.outputs.token }} | ||
run: | | ||
CURR_VERSION=$(grep -o 'version=\"[0-9.]*\"' setup.py | sed "s/version=\"\([0-9.]*\)\"/\1/") | ||
# We tagged the release branch first in bump_version.yml | ||
# to allow tests to pass; now moving it to develop so | ||
# it can be a part of its history | ||
git push --delete origin "v${CURR_VERSION}" | ||
git tag "v${CURR_VERSION}" HEAD | ||
git push origin tag "v${CURR_VERSION}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# This workflow is called by the start release workflow to bump this | ||
# repo's semgrep version to the newly release version; triggered by | ||
# the start-release workflow. | ||
|
||
jobs: | ||
bump-version: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
id-token: write | ||
contents: write | ||
pull-requests: write | ||
checks: write | ||
env: | ||
NEW_SEMGREP_VERSION: ${{ github.event.inputs.version }} | ||
steps: | ||
- id: jwt | ||
env: | ||
EXPIRATION: 600 | ||
ISSUER: ${{ secrets.SEMGREP_CI_APP_ID }} | ||
PRIVATE_KEY: ${{ secrets.SEMGREP_CI_APP_KEY }} | ||
name: Get JWT for semgrep-ci GitHub App | ||
uses: docker://public.ecr.aws/y9k7q4m1/devops/cicd:latest | ||
yosefAlsuhaibani marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- id: token | ||
name: Get token for semgrep-ci GitHub App | ||
run: | | ||
TOKEN="$(curl -X POST \ | ||
-H "Authorization: Bearer ${{ steps.jwt.outputs.jwt }}" \ | ||
-H "Accept: application/vnd.github.v3+json" \ | ||
"https://api.github.com/app/installations/${{ secrets.SEMGREP_CI_APP_INSTALLATION_ID }}/access_tokens" | \ | ||
jq -r .token)" | ||
echo "::add-mask::$TOKEN" | ||
echo "token=$TOKEN" >> $GITHUB_OUTPUT | ||
|
||
- uses: actions/checkout@v4 | ||
with: | ||
token: ${{ steps.token.outputs.token }} | ||
|
||
- name: Bump version in this repo | ||
run: scripts/bump-version.sh "${NEW_SEMGREP_VERSION}" | ||
|
||
- name: Commit and push | ||
id: commit | ||
env: | ||
BRANCH: "gha/bump-version-${{ github.event.inputs.version }}-${{ github.run_id }}-${{ github.run_attempt }}" | ||
SUBJECT: "Bump setup to ${{ github.event.inputs.version }}" | ||
run: | | ||
git config user.name ${{ github.actor }} | ||
git config user.email ${{ github.actor }}@users.noreply.github.com | ||
git checkout -b $BRANCH | ||
git commit -am "$SUBJECT" | ||
git tag "v${NEW_SEMGREP_VERSION}" HEAD | ||
git remote -vv | ||
git push --set-upstream origin $BRANCH | ||
git push origin tag "v$NEW_SEMGREP_VERSION" | ||
echo "branch=$BRANCH" >> $GITHUB_OUTPUT | ||
echo "subject=$SUBJECT" >> $GITHUB_OUTPUT | ||
|
||
- name: Create PR | ||
id: open-pr | ||
env: | ||
SOURCE: "${{ steps.commit.outputs.branch }}" | ||
TARGET: "${{ github.event.repository.default_branch }}" | ||
TITLE: "chore: update pre-commit to semgrep ${{ inputs.version }}" | ||
GITHUB_TOKEN: ${{ steps.token.outputs.token }} | ||
VERSION: "${{ inputs.version }}" | ||
run: | | ||
# check if the branch already has a pull request open | ||
if gh pr list --head ${SOURCE} | grep -vq "no pull requests"; then | ||
# pull request already open | ||
echo "pull request from SOURCE ${SOURCE} to TARGET ${TARGET} is already open"; | ||
echo "cancelling release" | ||
exit 1 | ||
fi | ||
# open new pull request with the body of from the local template. | ||
res=$(gh pr create --title "${TITLE}" --body "Bump Semgrep Version to ${VERSION}" \ | ||
--base "${TARGET}" --head "${SOURCE}") | ||
|
||
name: bump-version | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
version: | ||
description: "Version of semgrep to use" | ||
required: true | ||
type: string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/sh | ||
|
||
VERSION=$1 | ||
OLD_VERSION=$(grep -o 'version=\"[0-9.]*\"' setup.py | sed "s/version=\"\([0-9.]*\)\"/\1/") | ||
|
||
# Do text substitution in setup.py & README.md | ||
sed "s/$OLD_VERSION/$VERSION/" setup.py > tmp | ||
mv tmp setup.py | ||
sed "s/$OLD_VERSION/$VERSION/" README.md > tmp | ||
mv tmp README.md | ||
sed "s/$OLD_VERSION/$VERSION/" .pre-commit-config.yaml > tmp | ||
mv tmp .pre-commit-config.yaml |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this always triggers for
semgrep-ci[bot]
, let's just keep in mind we may need to narrow this to also require the PR title ischore: release
or whatever if we run into additional cases we want this bot to make a PR here. Seems fine for now though.