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

Conversation

tjgurwara99
Copy link
Member

@tjgurwara99 tjgurwara99 commented Dec 14, 2022

A new CodeQL CLI gets released (roughly) every 2 weeks1, which requires some minor updates to the extension. At the time of writing, whoever first determines that a new version of CLI has been released manually updates the version number in some places within this repository. This PR aims to reduce the manual step of updating occurrences of the old CLI version from select files so that they remain up to date for our integration tests. Note that the removal of support of CLI version is a scenario where this newly added script might cause some issues and I'm open to gathering ideas on how to tackle the time when we have to drop support for certain versions.

NOTE for maintainers: This script also requires a newly generated PAT for it to create a PULL request to update the workflow file. Therefore the Bump CLI version workflow is expected to break until a new secret WORKFLOW_TOKEN is added to the repository which would have as its value a PAT with the workflow permission.

Checklist

  • CHANGELOG.md has been updated to incorporate all user visible changes made by this pull request.
  • Issues have been created for any UI or other user-facing changes made by this pull request.

Footnotes

  1. In general, there's a minor version bump every quarter, which requires an extra step: remove old unsupported version of the CLI from our testing matrix. (We stop testing once we no longer support a version of GHES that shipped with that CLI. That means we only need to support 4 minor versions back, since that's how many GHES releases we support.)

@tjgurwara99 tjgurwara99 marked this pull request as ready for review December 14, 2022 15:14
@tjgurwara99 tjgurwara99 requested a review from a team as a code owner December 14, 2022 15:14
Copy link
Contributor

@aeisenberg aeisenberg left a comment

Choose a reason for hiding this comment

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

Also, just realized there is a problem if this workflow runs multiple times. If there is an open PR generated by this workflow, and the workflow runs again, trying to create a new PR, it will fail. I have an example of how we handle this in other repos.

@aeisenberg
Copy link
Contributor

Here is an action from a private repo that you (@tjgurwara99) should have access to. We use this to create a PR for a particular branch and close any other PRs for that branch if they are open. It might be overkill for this case, but you can still use this or copy pieces of this for this PR. https://github.com/github/semmle-code/blob/main/.github/actions/create-unique-pr/action.yml

@adityasharad
Copy link
Contributor

High-level comment: I wonder if keeping a separate JSON file with the list of CLI versions would help. The various tests could load that file to determine what CLI versions to test against. Then your PR would only need to modify that file (and you can skip creating the PR if there is no diff). This saves you the logic of having to sed-replace the old and new versions within various workflows and test scripts, and allows us to update the entire supported version range, rather than just the last two versions.

@tjgurwara99 tjgurwara99 marked this pull request as draft December 14, 2022 20:07
@tjgurwara99 tjgurwara99 force-pushed the main branch 11 times, most recently from 84918c8 to 8460034 Compare December 14, 2022 20:45
@tjgurwara99 tjgurwara99 force-pushed the main branch 6 times, most recently from b79d21a to 8e532e0 Compare December 14, 2022 22:23
@tjgurwara99 tjgurwara99 force-pushed the main branch 2 times, most recently from 2ad5584 to e296dba Compare December 14, 2022 22:49
- name: Commit, Push and Open a PR
uses: ./.github/actions/create-pr
with:
token: ${{ secrets.GITHUB_TOKEN }}
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the token doesn't have permission to push. I would think that contents: write should be enough.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's the right permission, but it won't work while this PR runs from a fork (by design). All write permissions get downgraded to read on forks.

COMMIT_MESSAGE: ${{ inputs.commit-message }}
HEAD_BRANCH: ${{ inputs.head-branch }}
BASE_BRANCH: ${{ inputs.base-branch }}
GH_TOKEN: ${{ inputs.token }}
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this needs to change to GITHUB_TOKEN so that the git commands can work.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think, the checkout step has already taken care of the ambiguity. Both GH_TOKEN and GITHUB_TOKEN work 😄 - I also think there might actually be no need for this since the GH_TOKEN is not being used in this action at all...

Copy link
Contributor

Choose a reason for hiding this comment

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

You need it for gh pr create.

Copy link
Member Author

@tjgurwara99 tjgurwara99 Dec 19, 2022

Choose a reason for hiding this comment

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

Yes, but this is after the checkout step which sets up the whole gh cli stuff right? We're calling it as a composite step in another action, and this itself is not a standalone action I believe 😅 Unless I'm mistaken 😓

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think so. I believe the checkout step sets up Git, and uses the token information to set up Git remotes and credentials, but does not do gh auth for the CLI. I believe the CLI will still be expecting a token in GH/GITHUB_TOKEN and will attempt interactive auth if that's missing (which you don't want in CI).

Copy link
Member Author

Choose a reason for hiding this comment

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

Cool, I'll keep it as it is then 😄

@tjgurwara99 tjgurwara99 requested a review from aeisenberg January 9, 2023 11:05
Copy link
Contributor

@aeisenberg aeisenberg left a comment

Choose a reason for hiding this comment

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

We need to handle the case where the minor version has changed. Short term, it's ok just to fail this workflow, but it would be nice to handle it gracefully.

pull_request:
branches: [main]
paths:
- .github/actions/create-pr/action.yml
Copy link
Contributor

Choose a reason for hiding this comment

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

Add this file as well.

Suggested change
- .github/actions/create-pr/action.yml
- .github/actions/create-pr/action.yml
- .github/workflows/bump-cli.yml

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is the last change that needs to be done before we can merge.

echo "PREVIOUS_VERSION=$PREVIOUS_VERSION" >> $GITHUB_ENV

sed -i "s/$PREVIOUS_VERSION/$LATEST_VERSION/g" supported_cli_versions.json
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.

Fixing this can be done at a later time.

Comment on lines +6 to +8
LATEST_VERSION=$(echo $VERSIONS | awk '{ print $1 }')
PREVIOUS_VERSION=$(echo $VERSIONS | awk '{ print $2 }')

Copy link
Contributor

Choose a reason for hiding this comment

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

When we do a minor version bump, we need to add the new version instead of replacing it.

Doing something like this can check if the minor version has changed:

LATEST_MINOR_VERSION="$(echo $LATEST_VERSION | awk 'BEGIN{FS=".";}{print $1$2}')"
PREVIOUS_MINOR_VERSION="$(echo $PREVIOUS_VERSION | awk 'BEGIN{FS=".";}{print $1$2}')"

if [ $LATEST_MINOR_VERSION != $PREVIOUS_MINOR_VERSION ];
then
   # handle case where minor version is changed
else
  # handle case where patch version is changed
fi

Copy link
Member Author

Choose a reason for hiding this comment

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

So the list of versions in supported_cli_versions.json is expanding every time we have a minor version bump? For example, if we have the following in the file

[
  "v2.11.5",
  "v2.7.6",
  "v2.8.5",
  "v2.9.4",
  "v2.10.5",
  "nightly"
]

and a version v2.11.6 has been released. Do we want to add that like the following?

[
  "v2.11.6", // this is the new version that got added
  "v2.11.5",
  "v2.7.6",
  "v2.8.5",
  "v2.9.4",
  "v2.10.5",
  "nightly"
]

Copy link
Contributor

Choose a reason for hiding this comment

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

v2.11.5 -> v2.11.6 would be a patch version bump, so in that case we want to replace!

The minor version bump would be v2.12.0 in this case, so we want to add it:

[
  "v2.12.0", // this is the new minor version that got added
  "v2.11.5",
  "v2.7.6",
  "v2.8.5",
  "v2.9.4",
  "v2.10.5",
  "nightly"
]

(Or even, we could add the new minor version and remove the oldest one (i.e. v.2.7.6).)

Copy link
Member

Choose a reason for hiding this comment

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

I don't think we can actually remove 2.7.6. The removal depends on the support GHES versions and GHES 3.3 is still supported. GHES 3.3 recommends CodeQL 2.7.6, so we can't remove that version yet. In general, I don't think we can remove a version automatically because it's not strictly aligned with the CodeQL CLI releases.

Copy link
Contributor

@shati-patel shati-patel Jan 12, 2023

Choose a reason for hiding this comment

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

GHES 3.3 is only supported for another 6 days (2023-01-18), so it kind of aligns with the CodeQL CLI (give or take 1 week 😄). But we don't have to automate the removal (or at least not in this PR) if we want to keep that separate/manual! 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Lol, I always get confused with semver 😂 For some reason I thought number after the second dot was minor release 😅

I think the removal of a version should be done through a separate workflow/action - from what I can tell, there doesn't seem to be an automated way of telling the which version should be removed. I also think that given a manual trigger with the some inputs (like for example in the image below) and manually adding the version to remove would be better unless we want to completely automate it which may not be as simple or quick 😄 Let me know though whichever way is preferred and I can think on what I can do. PS: I think this issue was for the patch release being released every two weeks or so, so this might benefit from a separate issue which I can take (this PR has been open for a while now - I want to close it 😂 of course if it meets the acceptable standards 😉)

Copy link
Contributor

Choose a reason for hiding this comment

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

Good points @tjgurwara99. I expect that this workflow will always be triggered manually since the timing of when to run this workflow depends on a bunch of human decisions.

I'm personally fine with focusing on patch releases for now and working on a new PR to add minor version bumps. I think we can avoid creating a second workflow for minor version bumps and handle that with a new set of inputs.

And removing releases when a GHES version drops out of support is probably something that should be done manually since it also means we can remove certain feature flags that only pertain to the older version.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've added the issue and assigned it to myself 😄 will get to it whenever I get time

Copy link
Contributor

@aeisenberg aeisenberg left a comment

Choose a reason for hiding this comment

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

Also, please keep track of the follow-up changes for this PR. Nice work.

pull_request:
branches: [main]
paths:
- .github/actions/create-pr/action.yml
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is the last change that needs to be done before we can merge.

@tjgurwara99
Copy link
Member Author

I don't know why the workflow Build Extension / Test is failing - anyone has any insights on this?

@shati-patel
Copy link
Contributor

I don't know why the workflow Build Extension / Test is failing - anyone has any insights on this?

Tempted to say it's just flaky 😅 Have you tried re-running?

Copy link
Contributor

@aeisenberg aeisenberg left a comment

Choose a reason for hiding this comment

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

Great!

Once this is merged, can you do a trial of the new workflow to see how it goes? I'm not sure if you have any examples elsewhere.

@tjgurwara99
Copy link
Member Author

tjgurwara99 commented Jan 13, 2023

Once this is merged, can you do a trial of the new workflow to see how it goes?

Sure, if by trial you mean sending a workflow dispatch 😄

I'm not sure if you have any examples elsewhere.

The example run was in my fork here. I'm fairly confident that it would work once the workflow token changes from read permission to write permission but I can test it properly in this repo once it's merged. EDIT: I'm gonna eat my words - it turned out that the file was moved and my fork wasn't synced so it started failing without me noticing once I synced it 😓

Also, I don't have the permission to merge this PR, could you merge it please?

@aeisenberg
Copy link
Contributor

Sure. I can merge. The latest test failures seem unrelated, but concerning.

@aeisenberg aeisenberg enabled auto-merge January 13, 2023 21:01
@aeisenberg aeisenberg merged commit ecbb0fb into github:main Jan 13, 2023
@aeisenberg
Copy link
Contributor

Hmmm...they seem like flakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants