-
Notifications
You must be signed in to change notification settings - Fork 432
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: CI: add actionlint action, fix actions (#3156)
I keep messing things up, so time for some guard rails, so check them using [actionlint](https://github.com/raven-actions/actionlint). This also runs [shellcheck](https://www.shellcheck.net/) on the files. Shellcheck is a bit picky about putting double quotes around variables, and will flag many cases where we know it’s safe, but why not simply always write the safer variant. Unfortunately, actionlint does not (yet) check `actions/github-script` scripts, which is unfortunate. Maybe they will in the future (rhysd/actionlint#389)
- Loading branch information
Showing
3 changed files
with
56 additions
and
32 deletions.
There are no files selected for viewing
This file contains 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,22 @@ | ||
name: Actionlint | ||
on: | ||
push: | ||
branches: | ||
- 'master' | ||
paths: | ||
- '.github/**' | ||
pull_request: | ||
paths: | ||
- '.github/**' | ||
merge_group: | ||
|
||
jobs: | ||
actionlint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: actionlint | ||
uses: raven-actions/actionlint@v1 | ||
with: | ||
pyflakes: false # we do not use python scripts |
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -107,7 +107,7 @@ jobs: | |
git -C lean4.git remote add nightly https://github.com/leanprover/lean4-nightly.git | ||
git -C lean4.git fetch nightly '+refs/tags/nightly-*:refs/tags/nightly-*' | ||
git -C lean4.git tag --merged "${{ steps.workflow-info.outputs.sourceHeadSha }}" --list "nightly-*" \ | ||
| sort -rV | head -n 1 | sed "s/^nightly-*/MOST_RECENT_NIGHTLY=/" | tee -a $GITHUB_ENV | ||
| sort -rV | head -n 1 | sed "s/^nightly-*/MOST_RECENT_NIGHTLY=/" | tee -a "$GITHUB_ENV" | ||
- name: 'Setup jq' | ||
if: ${{ steps.workflow-info.outputs.pullRequestNumber != '' }} | ||
|
@@ -126,22 +126,22 @@ jobs: | |
if [ "$NIGHTLY_SHA" = "$MERGE_BASE_SHA" ]; then | ||
echo "The merge base of this PR coincides with the nightly release" | ||
REMOTE_BRANCHES=$(git ls-remote -h https://github.com/leanprover-community/mathlib4.git nightly-testing-$MOST_RECENT_NIGHTLY) | ||
REMOTE_BRANCHES="$(git ls-remote -h https://github.com/leanprover-community/mathlib4.git nightly-testing-"$MOST_RECENT_NIGHTLY")" | ||
if [[ -n "$REMOTE_BRANCHES" ]]; then | ||
echo "... and Mathlib has a 'nightly-testing-$MOST_RECENT_NIGHTLY' branch." | ||
MESSAGE="" | ||
else | ||
echo "... but Mathlib does not yet have a 'nightly-testing-$MOST_RECENT_NIGHTLY' branch." | ||
MESSAGE="- ❗ Mathlib CI can not be attempted yet, as the 'nightly-testing-$MOST_RECENT_NIGHTLY' branch does not exist there yet. We will retry when you push more commits. If you rebase your branch onto `nightly-with-mathlib`, Mathlib CI should run now." | ||
MESSAGE="- ❗ Mathlib CI can not be attempted yet, as the \`nightly-testing-$MOST_RECENT_NIGHTLY\` branch does not exist there yet. We will retry when you push more commits. If you rebase your branch onto \`nightly-with-mathlib\`, Mathlib CI should run now." | ||
fi | ||
else | ||
echo "The most recently nightly tag on this branch has SHA: $NIGHTLY_SHA" | ||
echo "but 'git merge-base origin/master HEAD' reported: $MERGE_BASE_SHA" | ||
git -C lean4.git log -10 origin/master | ||
MESSAGE="- ❗ Mathlib CI will not be attempted unless your PR branches off the 'nightly-with-mathlib' branch." | ||
MESSAGE="- ❗ Mathlib CI will not be attempted unless your PR branches off the \`nightly-with-mathlib\` branch." | ||
fi | ||
if [[ -n "$MESSAGE" ]]; then | ||
|
@@ -153,12 +153,12 @@ jobs: | |
# so keep in sync | ||
# Use GitHub API to check if a comment already exists | ||
existing_comment=$(curl -L -s -H "Authorization: token ${{ secrets.MATHLIB4_BOT }}" \ | ||
existing_comment="$(curl -L -s -H "Authorization: token ${{ secrets.MATHLIB4_BOT }}" \ | ||
-H "Accept: application/vnd.github.v3+json" \ | ||
"https://api.github.com/repos/leanprover/lean4/issues/${{ steps.workflow-info.outputs.pullRequestNumber }}/comments" \ | ||
| jq 'first(.[] | select(.body | test("^- . Mathlib") or startswith("Mathlib CI status")) | select(.user.login == "leanprover-community-mathlib4-bot"))') | ||
existing_comment_id=$(echo "$existing_comment" | jq -r .id) | ||
existing_comment_body=$(echo "$existing_comment" | jq -r .body) | ||
| jq 'first(.[] | select(.body | test("^- . Mathlib") or startswith("Mathlib CI status")) | select(.user.login == "leanprover-community-mathlib4-bot"))')" | ||
existing_comment_id="$(echo "$existing_comment" | jq -r .id)" | ||
existing_comment_body="$(echo "$existing_comment" | jq -r .body)" | ||
if [[ "$existing_comment_body" != *"$MESSAGE"* ]]; then | ||
MESSAGE="$MESSAGE ($(date "+%Y-%m-%d %H:%M:%S"))" | ||
|
@@ -190,13 +190,13 @@ jobs: | |
else | ||
echo "The message already exists in the comment body." | ||
fi | ||
echo "mathlib_ready=false" >> $GITHUB_OUTPUT | ||
echo "mathlib_ready=false" >> "$GITHUB_OUTPUT" | ||
else | ||
echo "mathlib_ready=true" >> $GITHUB_OUTPUT | ||
echo "mathlib_ready=true" >> "$GITHUB_OUTPUT" | ||
fi | ||
- name: Report mathlib base | ||
if: ${{ steps.workflow-info.outputs.pullRequestNumber != '' }} && steps.ready.outputs.mathlib_ready == 'true' | ||
if: ${{ steps.workflow-info.outputs.pullRequestNumber != '' && steps.ready.outputs.mathlib_ready == 'true' }} | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
|
@@ -220,7 +220,7 @@ jobs: | |
- name: Cleanup workspace | ||
if: steps.workflow-info.outputs.pullRequestNumber != '' && steps.ready.outputs.mathlib_ready == 'true' | ||
run: | | ||
sudo rm -rf * | ||
sudo rm -rf ./* | ||
# Checkout the mathlib4 repository with all branches | ||
- name: Checkout mathlib4 repository | ||
|
@@ -240,17 +240,17 @@ jobs: | |
git config user.email "[email protected]" | ||
if git branch -r | grep -q "nightly-testing-${MOST_RECENT_NIGHTLY}"; then | ||
BASE=nightly-testing-${MOST_RECENT_NIGHTLY} | ||
BASE="nightly-testing-${MOST_RECENT_NIGHTLY}" | ||
else | ||
echo "This shouldn't be possible: couldn't find a 'nightly-testing-${MOST_RECENT_NIGHTLY}' branch at Mathlib. Falling back to 'nightly-testing'." | ||
BASE=nightly-testing | ||
fi | ||
echo "Using base branch: $BASE" | ||
git checkout $BASE | ||
git checkout "$BASE" | ||
EXISTS=$(git ls-remote --heads origin lean-pr-testing-${{ steps.workflow-info.outputs.pullRequestNumber }} | wc -l) | ||
EXISTS="$(git ls-remote --heads origin lean-pr-testing-${{ steps.workflow-info.outputs.pullRequestNumber }} | wc -l)" | ||
echo "Branch exists: $EXISTS" | ||
if [ "$EXISTS" = "0" ]; then | ||
echo "Branch does not exist, creating it." | ||
|
@@ -262,7 +262,7 @@ jobs: | |
echo "Branch already exists, pushing an empty commit." | ||
git checkout lean-pr-testing-${{ steps.workflow-info.outputs.pullRequestNumber }} | ||
# The Mathlib `nightly-testing` or `nightly-testing-YYYY-MM-DD` branch may have moved since this branch was created, so merge their changes. | ||
git merge $BASE --strategy-option ours --no-commit --allow-unrelated-histories | ||
git merge "$BASE" --strategy-option ours --no-commit --allow-unrelated-histories | ||
git commit --allow-empty -m "Trigger CI for https://github.com/leanprover/lean4/pull/${{ steps.workflow-info.outputs.pullRequestNumber }}" | ||
fi | ||
|