Merge pull request #1871 from tjgurwara99/main

Workflow to automatically bump cli version if different from the current version
This commit is contained in:
Andrew Eisenberg
2023-01-13 13:14:14 -08:00
committed by GitHub
5 changed files with 155 additions and 2 deletions

82
.github/actions/create-pr/action.yml vendored Normal file
View File

@@ -0,0 +1,82 @@
name: Create a PR if one doesn't exists
description: >
Creates a commit with the current changes to the repo, and opens a PR for that commit. If
any PR with the same title exists, then this action is marked as succeeded.
inputs:
commit-message:
description: >
The message for the commit to be created.
required: true
title:
description: >
The title of the PR. If empty, the title and body will be determined from the commit message.
default: ''
required: false
body:
description: >
The body (description) of the PR. The `title` input must be specified in order for this input to be used.
default: ''
required: false
head-branch:
description: >
The name of the branch to hold the new commit. If an existing open PR with the same head
branch exists, the new branch will be force-pushed to that PR instead of creating a new PR.
required: true
base-branch:
description: >
The base branch to target with the new PR.
required: true
token:
description: |
The GitHub token to use. It must have enough privileges to
make API calls to create and close pull requests.
required: true
runs:
using: composite
steps:
- name: Update git config
shell: bash
run: |
git config --global user.email "github-actions@github.com"
git config --global user.name "github-actions[bot]"
- name: Commit, Push and Open PR
shell: bash
env:
COMMIT_MESSAGE: ${{ inputs.commit-message }}
HEAD_BRANCH: ${{ inputs.head-branch }}
BASE_BRANCH: ${{ inputs.base-branch }}
GH_TOKEN: ${{ inputs.token }}
TITLE: ${{ inputs.title }}
BODY: ${{ inputs.body }}
run: |
set -exu
if ! [[ $(git diff --stat) != '' ]]; then
exit 0 # exit early
fi
# stage changes in the working tree
git add .
git commit -m "$COMMIT_MESSAGE"
git checkout -b "$HEAD_BRANCH"
# CAUTION: gits history changes with the following
git push --force origin "$HEAD_BRANCH"
PR_JSON=$(gh pr list --state open --json number --head "$HEAD_BRANCH")
if [[ $? -ne 0 ]]; then
echo "Failed to fetch existing PRs."
exit 1
fi
PR_NUMBERS=$(echo $PR_JSON | jq '. | length')
if [[ $PR_NUMBERS -ne 0 ]]; then
echo "Found existing open PR: $PR_NUMBERS"
exit 0
fi
gh pr create --head "$HEAD_BRANCH" --base "$BASE_BRANCH" --title "$TITLE" --body "$BODY" --assignee ${{ github.actor }}
if [[ $? -ne 0 ]]; then
echo "Failed to create new PR."
exit 1
fi

39
.github/workflows/bump-cli.yml vendored Normal file
View File

@@ -0,0 +1,39 @@
name: Bump CLI version
on:
workflow_dispatch:
pull_request:
branches: [main]
paths:
- .github/actions/create-pr/action.yml
- .github/workflows/bump-cli.yml
schedule:
- cron: 0 0 */14 * * # run every 14 days
permissions:
contents: write
pull-requests: write
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Bump CLI
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
scripts/replace-cli-version.sh
- name: Commit, Push and Open a PR
uses: ./.github/actions/create-pr
with:
token: ${{ secrets.GITHUB_TOKEN }}
base-branch: main
head-branch: github-action/bump-cli
commit-message: Bump CLI version from ${{ env.PREVIOUS_VERSION }} to ${{ env.LATEST_VERSION }} for integration tests
title: Bump CLI Version to ${{ env.LATEST_VERSION }} for integration tests
body: >
Bumps CLI version from ${{ env.PREVIOUS_VERSION }} to ${{ env.LATEST_VERSION }}

View File

@@ -183,14 +183,25 @@ jobs:
run: |
npm run integration
set-matrix:
name: Set Matrix for cli-test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set the variables
id: set-variables
run: echo "cli-versions=$(cat ./supported_cli_versions.json | jq -rc)" >> $GITHUB_OUTPUT
outputs:
cli-versions: ${{ steps.set-variables.outputs.cli-versions }}
cli-test:
name: CLI Test
runs-on: ${{ matrix.os }}
needs: [find-nightly]
needs: [find-nightly, set-matrix]
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
version: ['v2.7.6', 'v2.8.5', 'v2.9.4', 'v2.10.5', 'v2.11.6', 'nightly']
version: ${{ fromJson(needs.set-matrix.outputs.cli-versions) }}
fail-fast: false
env:
CLI_VERSION: ${{ matrix.version }}

13
scripts/replace-cli-version.sh Executable file
View File

@@ -0,0 +1,13 @@
#!/bin/bash
VERSIONS=$(gh api -H "Accept: application/vnd.github+json" /repos/github/codeql-cli-binaries/releases | jq -r '.[].tag_name' | head -2)
# we are exporting these variables so that we can access these variables in the workflow
LATEST_VERSION=$(echo $VERSIONS | awk '{ print $1 }')
PREVIOUS_VERSION=$(echo $VERSIONS | awk '{ print $2 }')
echo "LATEST_VERSION=$LATEST_VERSION" >> $GITHUB_ENV
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/test/vscode-tests/ensureCli.ts

View File

@@ -0,0 +1,8 @@
[
"v2.11.6",
"v2.7.6",
"v2.8.5",
"v2.9.4",
"v2.10.5",
"nightly"
]