Skip to content

Workflow to automatically bump cli version if different from the current version #1871

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

Merged
merged 14 commits into from
Jan 13, 2023
Merged
Changes from 1 commit
Commits
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
44 changes: 44 additions & 0 deletions .github/workflows/bump-cli.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Bump CLI version
on:
push:
branches: [main]
pull_request:
branches: [main]
schedule:
- cron: 0 0 */14 * * # run every 14 days

jobs:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a permissions block to this job or workflow, with contents: write and pull-requests: write permissions. That should be enough to allow the workflow to create a PR when run from the parent repo. It will still not allow the workflow to create a PR when run from a fork, which I think is preferable.

With this change, I think we can avoid changing the setting to grant read+write permissions to workflows on PRs from forks.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh ok. I did try that but it failed, I thought maybe it still needed that permission - didn't know it was because it was from the fork, it got rejected. That's great, thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It still won't work on your fork, which is ok. The write permission in the workflow gets downgraded to read on forks, thanks to the repo setting you noticed. It's safer to have read-only permissions on forks than trying to reason about whether we are granting the correct set of permissions to contributor PRs from forks.

If you're making automation changes in future it may be easier to use a branch on the parent repo (otherwise forks are totally fine).

build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 1
token: ${{ secrets.WORKFLOW_TOKEN }}
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -qq jq
sudo apt-get install gh
shell: bash
- name: Bump CLI
env:
GH_TOKEN: ${{ github.token }}
run: |
scripts/replace-cli-version.sh
- name: Push changes to a branch
env:
GH_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
run: |
git config user.name github-actions
git config user.email github-actions@github.com
git checkout -b bump-cli
if [[ `git status --porcelain` ]]; then
git add .
git commit -m "automatically bump cli version"
git push --set-upstream origin bump-cli
git push
gh pr create --title "Bump CLI Version for integration tests" --body ""
fi
9 changes: 9 additions & 0 deletions scripts/replace-cli-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

VERSIONS=$(gh api -H "Accept: application/vnd.github+json" /repos/github/codeql-cli-binaries/releases | jq '.[].tag_name' | head -2)

LATEST_VERSION=$(echo $VERSIONS | awk '{ print $1 }' | sed "s/\"//g")
PREVIOUS_VERSION=$(echo $VERSIONS | awk '{ print $2 }' | sed "s/\"//g")

sed -i "s/$PREVIOUS_VERSION/$LATEST_VERSION/g" .github/workflows/main.yml
sed -i "s/$PREVIOUS_VERSION/$LATEST_VERSION/g" extensions/ql-vscode/src/vscode-tests/ensureCli.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this, or can ensureCli.ts now read from supported_cli_versions.json?

Copy link
Member Author

@tjgurwara99 tjgurwara99 Dec 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can probably read from that supported_cli_version.json file, I didn't touch it because I've been unable to run the project directly in my local 😂 which was why I asked yesterday to help me with the setup but didn't get time to try the setup steps suggested in the thread 😓 I was hoping that can be done in a separate PR once I have the local test environment set up properly

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to help if you have setup problems.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing this can be done at a later time.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an issue to track this.