Skip to content
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/autoapprove.yml
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]'}}
Comment thread
yosefAlsuhaibani marked this conversation as resolved.
Outdated
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 }}
82 changes: 82 additions & 0 deletions .github/workflows/bump_version.yml
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
Comment thread
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
43 changes: 43 additions & 0 deletions .github/workflows/tag-version.yaml
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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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

  • bump_version.yml: Commits on a branch, pushes the branch & tags a commit on the branch
  • autoapprove.yml: If PR is made by semgrep-ci[bot], approve & wait for checks to pass; then auth as semgrep-ci[bot], move the tag to develop. (delete the tag made on the branch, then push a tag on develop)

10 changes: 10 additions & 0 deletions scripts/bump-version.sh
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
Comment thread
yosefAlsuhaibani marked this conversation as resolved.
sed "s/$OLD_VERSION/$VERSION/" .pre-commit-config.yaml > tmp
mv tmp .pre-commit-config.yaml
4 changes: 4 additions & 0 deletions scripts/tag-version.sh
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/")
Comment thread
yosefAlsuhaibani marked this conversation as resolved.
Outdated

git tag "v${CURR_VERSION}" HEAD
git push origin tag "v${CURR_VERSION}"
Comment thread
yosefAlsuhaibani marked this conversation as resolved.
Outdated