-
Notifications
You must be signed in to change notification settings - Fork 380
Add workflow for updating release used by start-proxy
#2941
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
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
6b9b66d
Add workflow for updating release used by `start-proxy`
mbg 0180811
Use environment variable to store release tag
mbg e8ad3af
Add `push` trigger for testing
mbg 286556a
Fix `pr_title` quotes
mbg 7ca4105
Fix branch name
mbg 37a3fcc
Improve PR title formatting
mbg c55fb0a
Fix `pr_body` contents
mbg fcd0ad4
Start with `main`
mbg 46cafbc
Add missing `v` to regex
mbg e044b15
Check that the release tag has the expected format
mbg cce0287
Check that the release exists
mbg 9ee60a6
Run on Ubuntu
mbg 6a3692d
Construct target branch name in `checks` step
mbg 0cec254
Use `--dry-run` for non-`workflow_dispatch` events
mbg 6e22e41
Add reminder to mark PR as ready for review to trigger CI
mbg bbfc5be
Replace inline expressions with environment variables
mbg 2e3b93f
Remove push trigger that was used for testing
mbg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
name: Update dependency proxy release assets | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
tag: | ||
description: "The tag of CodeQL Bundle release that contains the proxy binaries as release assets" | ||
type: string | ||
required: true | ||
|
||
jobs: | ||
update: | ||
name: Update code and create PR | ||
timeout-minutes: 15 | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write # needed to push the updated files | ||
pull-requests: write # needed to create the PR | ||
env: | ||
RELEASE_TAG: ${{ inputs.tag }} | ||
steps: | ||
- name: Check release tag format | ||
id: checks | ||
shell: bash | ||
run: | | ||
if ! [[ $RELEASE_TAG =~ ^codeql-bundle-v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | ||
echo "Invalid release tag: expected a CodeQL bundle tag in the 'codeql-bundle-vM.N.P' format." | ||
exit 1 | ||
fi | ||
|
||
echo "target_branch=dependency-proxy/$RELEASE_TAG" >> $GITHUB_OUTPUT | ||
|
||
- name: Check that the release exists | ||
shell: bash | ||
env: | ||
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" | ||
run: | | ||
(gh release view --repo "$GITHUB_REPOSITORY" --json "assets" "$RELEASE_TAG" && echo "Release found.") || exit 1 | ||
|
||
- name: Install Node | ||
uses: actions/setup-node@v4 | ||
|
||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 # ensure we have all tags and can push commits | ||
ref: main | ||
|
||
- name: Update git config | ||
shell: bash | ||
run: | | ||
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
git config --global user.name "github-actions[bot]" | ||
|
||
- name: Update release tag and version | ||
shell: bash | ||
run: | | ||
NOW=$(date +"%Y%m%d%H%M%S") # only used to make sure we don't fetch stale binaries from the toolcache | ||
sed -i "s|https://github.com/github/codeql-action/releases/download/codeql-bundle-v[0-9.]\+/|https://github.com/github/codeql-action/releases/download/$RELEASE_TAG/|g" ./src/start-proxy-action.ts | ||
sed -i "s/\"v2.0.[0-9]\+\"/\"v2.0.$NOW\"/g" ./src/start-proxy-action.ts | ||
|
||
- name: Compile TypeScript and commit changes | ||
shell: bash | ||
env: | ||
TARGET_BRANCH: ${{ steps.checks.outputs.target_branch }} | ||
run: | | ||
set -exu | ||
git checkout -b "$TARGET_BRANCH" | ||
|
||
npm run build | ||
git add ./src/start-proxy-action.ts | ||
git add ./lib | ||
git commit -m "Update release used by \`start-proxy\` action" | ||
|
||
- name: Push changes and open PR | ||
shell: bash | ||
env: | ||
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" | ||
TARGET_BRANCH: ${{ steps.checks.outputs.target_branch }} | ||
PR_FLAG: ${{ (github.event_name == 'workflow_dispatch' && '--draft') || '--dry-run' }} | ||
run: | | ||
set -exu | ||
pr_title="Update release used by \`start-proxy\` to \`$RELEASE_TAG\`" | ||
pr_body=$(cat << EOF | ||
This PR updates the \`start-proxy\` action to use the private registry proxy binaries that | ||
are attached as release assets to the \`$RELEASE_TAG\` release. | ||
|
||
|
||
Please do the following before merging: | ||
|
||
- [ ] Verify that the changes to the code are correct. | ||
- [ ] Mark the PR as ready for review to trigger the CI. | ||
EOF | ||
) | ||
|
||
git push origin "$TARGET_BRANCH" | ||
gh pr create \ | ||
--head "$TARGET_BRANCH" \ | ||
--base "main" \ | ||
--title "${pr_title}" \ | ||
--body "${pr_body}" \ | ||
$PR_FLAG |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we move this checkout earlier than the
Check that the release exists
step, thengh
will pick up the repository to query automatically, allowing us to drop the--repo
. Checkout is fast enough that it can go before the error checking IMO.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had considered that, but explicitly adding the
--repo
argument isn't much of an inconvenience so it makes more sense to me to perform the check first.