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