|
| 1 | +jobs: |
| 2 | + bump-version: |
| 3 | + runs-on: ubuntu-latest |
| 4 | + permissions: |
| 5 | + id-token: write |
| 6 | + contents: write |
| 7 | + pull-requests: write |
| 8 | + checks: write |
| 9 | + env: |
| 10 | + NEW_SEMGREP_VERSION: ${{ github.event.inputs.version }} |
| 11 | + steps: |
| 12 | + - id: jwt |
| 13 | + env: |
| 14 | + EXPIRATION: 600 |
| 15 | + ISSUER: ${{ secrets.SEMGREP_CI_APP_ID }} |
| 16 | + PRIVATE_KEY: ${{ secrets.SEMGREP_CI_APP_KEY }} |
| 17 | + name: Get JWT for semgrep-ci GitHub App |
| 18 | + uses: docker://public.ecr.aws/y9k7q4m1/devops/cicd:latest |
| 19 | + - id: token |
| 20 | + name: Get token for semgrep-ci GitHub App |
| 21 | + run: | |
| 22 | + TOKEN="$(curl -X POST \ |
| 23 | + -H "Authorization: Bearer ${{ steps.jwt.outputs.jwt }}" \ |
| 24 | + -H "Accept: application/vnd.github.v3+json" \ |
| 25 | + "https://api.github.com/app/installations/${{ secrets.SEMGREP_CI_APP_INSTALLATION_ID }}/access_tokens" | \ |
| 26 | + jq -r .token)" |
| 27 | + echo "::add-mask::$TOKEN" |
| 28 | + echo "token=$TOKEN" >> $GITHUB_OUTPUT |
| 29 | +
|
| 30 | + - uses: actions/checkout@v3 |
| 31 | + with: |
| 32 | + token: ${{ steps.token.outputs.token }} |
| 33 | + |
| 34 | + - name: Bump version in this repo |
| 35 | + run: scripts/bump-version.sh "$NEW_SEMGREP_VERSION" |
| 36 | + |
| 37 | + - name: Commit and push |
| 38 | + id: commit |
| 39 | + env: |
| 40 | + BRANCH: "gha/bump-version-${NEW_SEMGREP_VERSION}-${{ github.run_id }}-${{ github.run_attempt }}" |
| 41 | + SUBJECT: "Bump semgrep to ${NEW_SEMGREP_VERSION}" |
| 42 | + run: | |
| 43 | + git config user.name ${{ github.actor }} |
| 44 | + git config user.email ${{ github.actor }}@users.noreply.github.com |
| 45 | + git checkout -b $BRANCH |
| 46 | + git add . |
| 47 | + git commit -m "$SUBJECT" |
| 48 | + git tag $NEW_SEMGREP_VERSION $(git rev-parse HEAD) |
| 49 | + git push --set-upstream origin $BRANCH |
| 50 | + echo "branch=$BRANCH" >> $GITHUB_OUTPUT |
| 51 | + echo "subject=$SUBJECT" >> $GITHUB_OUTPUT |
| 52 | + - name: Create PR |
| 53 | + id: open-pr |
| 54 | + env: |
| 55 | + SOURCE: "${{ steps.commit.outputs.branch }}" |
| 56 | + TARGET: "${{ github.event.repository.default_branch }}" |
| 57 | + TITLE: "chore: Release Version ${{ inputs.version }}" |
| 58 | + GITHUB_TOKEN: ${{ steps.token.outputs.token }} |
| 59 | + VERSION: "${{ inputs.version }}" |
| 60 | + run: | |
| 61 | + # check if the branch already has a pull request open |
| 62 | + if gh pr list --head ${SOURCE} | grep -vq "no pull requests"; then |
| 63 | + # pull request already open |
| 64 | + echo "pull request from SOURCE ${SOURCE} to TARGET ${TARGET} is already open"; |
| 65 | + echo "cancelling release" |
| 66 | + exit 1 |
| 67 | + fi |
| 68 | + # open new pull request with the body of from the local template. |
| 69 | + res=$(gh pr create --title "${TITLE}" --body "Bump Semgrep Version to ${VERSION}" \ |
| 70 | + --base "${TARGET}" --head "${SOURCE}" --reviewer semgrep/cdx) |
| 71 | +
|
| 72 | +# commit & tag & push code |
| 73 | + |
| 74 | +git tag $VERSION $(git rev-parse HEAD) |
| 75 | +git push origin tag $VERSION |
| 76 | + |
| 77 | +name: bump-version |
| 78 | +on: |
| 79 | + workflow_dispatch: |
| 80 | + inputs: |
| 81 | + version: |
| 82 | + description: "Version of semgrep to use" |
| 83 | + required: true |
| 84 | + type: string |
0 commit comments