-
Notifications
You must be signed in to change notification settings - Fork 4
feat(automate): automate version bump for pre-commit repo #12
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
Changes from 24 commits
b8ef75a
a17c837
7de67c4
1c95ea9
91348e2
76e4641
1a3e71d
b56adb4
889a37e
7a29ca1
d456a8c
dc756c0
a2d5182
ccd1520
72cc2d1
478a0e2
01f5143
0b9d98e
6eb6af7
ef025e5
882a4d7
15aab20
9e3b0aa
76c6ece
6640368
780eef4
3b9f235
b7192c5
547aa2a
d8e84e3
4351df5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| name: github-actions auto-approve | ||
| on: pull_request_target | ||
|
|
||
| permissions: | ||
| pull-requests: write | ||
| contents: write | ||
|
|
||
| jobs: | ||
| approve-bot: | ||
| runs-on: ubuntu-latest | ||
| if: ${{ github.actor == 'github-actions' || github.actor == 'semgrep-ci[bot]'}} | ||
| steps: | ||
| - name: Enable auto-merge | ||
| run: gh pr merge --auto --squash "$PR_URL" | ||
| env: | ||
| PR_URL: ${{ github.event.pull_request.html_url }} | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| - name: Approve | ||
| run: gh pr review --approve "$PR_URL" | ||
| env: | ||
| PR_URL: ${{ github.event.pull_request.html_url }} | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| 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.
|
||
|
|
||
| - 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 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| jobs: | ||
| tag-version: | ||
| runs-on: ubuntu-latest | ||
| if: ${{contains(github.event.head_commit.message, 'Bump setup')}} | ||
| permissions: | ||
| id-token: write | ||
| contents: write | ||
| pull-requests: write | ||
| checks: write | ||
| 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 | ||
|
|
||
| - 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 | ||
| env: | ||
| GITHUB_TOKEN: ${{ steps.token.outputs.token }} | ||
| run: scripts/tag-version.sh "${NEW_SEMGREP_VERSION}" | ||
|
|
||
| name: tag-version | ||
| on: | ||
| push: | ||
| branches: | ||
| - develop | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What would happen here if we make multiple commits on a given version?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The thought behind this workflow is that it is ran only after the bump version workflow's PR is merged which is just one single squashed merge commit; I'm not sure if there is any more invariants I should be concerned about in this repo:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ( am still trying to debug this workflow as for some reason it does not trigger after an auto merge, at least thats what I saw in the test-pre-commit repo)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alright I've deleted this workflow: the way this is automated now is
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| 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 | ||
|
yosefAlsuhaibani marked this conversation as resolved.
|
||
| sed "s/$OLD_VERSION/$VERSION/" .pre-commit-config.yaml > tmp | ||
| mv tmp .pre-commit-config.yaml | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| CURR_VERSION=$(grep -o 'version=\"[0-9.]*\"' setup.py | sed "s/version=\"\([0-9.]*\)\"/\1/") | ||
|
yosefAlsuhaibani marked this conversation as resolved.
Outdated
|
||
|
|
||
| git tag "v${CURR_VERSION}" HEAD | ||
| git push origin tag "v${CURR_VERSION}" | ||
|
yosefAlsuhaibani marked this conversation as resolved.
Outdated
|
||
Uh oh!
There was an error while loading. Please reload this page.