Skip to content

Commit 7c73273

Browse files
authored
Merge pull request #169 from adityasharad/actions/update-submodule
Actions: Add manual workflow to update the CodeQL submodule
2 parents d060089 + f87d20a commit 7c73273

2 files changed

Lines changed: 78 additions & 1 deletion

File tree

‎.github/workflows/check-submodule-pointers.yml‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ on:
66
branches: [ main ]
77
pull_request:
88
branches: [ main ]
9+
types:
10+
- opened
11+
- synchronize
12+
- ready_for_review
13+
- reopened
914
schedule:
1015
- cron: '42 12 * * *'
1116

@@ -14,7 +19,7 @@ jobs:
1419
runs-on: ubuntu-latest
1520
if: github.repository == 'github/vscode-codeql-starter'
1621
steps:
17-
- uses: actions/checkout@v2
22+
- uses: actions/checkout@v3
1823

1924
- name: Compare submodule pointers to lgtm.com branch
2025
env:
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Ensures the `ql` submodule is up to date, creating a PR if necessary.
2+
name: Update CodeQL submodule
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
update-codeql-submodule:
8+
name: Update CodeQL submodule
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: write
12+
pull-requests: write
13+
env:
14+
# Unique branch name for each run of this workflow.
15+
BRANCH_NAME: 'update-codeql-submodule-${{ github.run_id }}-${{ github.run_attempt }}'
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v3
19+
with:
20+
fetch-depth: 1
21+
submodules: recursive
22+
23+
- name: Git config
24+
shell: bash
25+
run: |
26+
set -exu
27+
git config user.name "github-actions[bot]"
28+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
29+
30+
echo "Creating a new branch: ${BRANCH_NAME}"
31+
git checkout -b "${BRANCH_NAME}"
32+
33+
echo "Fetching refs"
34+
# Explicitly unshallow and fetch to ensure the submodule's remote ref is available.
35+
pushd ql
36+
git fetch --unshallow origin +lgtm.com:refs/remotes/origin/lgtm.com # must match branch name in gitmodules
37+
popd
38+
39+
- name: Update submodule
40+
id: update
41+
shell: bash
42+
run: |
43+
echo "CODEQL_SHA_BEFORE=$(git rev-parse @:./ql)" | tee -a "$GITHUB_ENV"
44+
45+
echo "Updating CodeQL submodule"
46+
git submodule update --init --remote
47+
48+
# Stage changes
49+
git add ql
50+
# Only commit if the working tree is not empty
51+
if [[ -n "$(git diff --stat --cached)" ]]; then
52+
echo "changed=true" | tee -a "$GITHUB_OUTPUT"
53+
echo "::notice::Submodule has changes to commit. Will create a PR."
54+
else
55+
echo "::notice::No changes to commit."
56+
fi
57+
58+
- name: Commit change and create PR
59+
if: steps.update.outputs.changed == 'true'
60+
shell: bash
61+
env:
62+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
63+
run: |
64+
git commit -m "Update CodeQL submodule"
65+
CODEQL_SHA_AFTER="$(git rev-parse @:./ql)"
66+
echo "CODEQL_SHA_AFTER=$CODEQL_SHA_AFTER"
67+
git push origin "$BRANCH_NAME"
68+
gh pr create \
69+
--title "Update CodeQL submodule" \
70+
--body "Submodule pointer updated from github/codeql@${CODEQL_SHA_BEFORE} to github/codeql@${CODEQL_SHA_AFTER}." \
71+
--draft \
72+
--head "$BRANCH_NAME"

0 commit comments

Comments
 (0)