Skip to content
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

feat: prototype update action #5

Merged
merged 2 commits into from
Feb 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: Check for updates

# This action will run `lean update` and try `lean build` if there is an available update.
# There are three possible outcomes:
# - No update available (silent)
# - Update available and build succeeds (open PR)
# - Update available and build fails (open issue)

on:
schedule:
- cron: "0 11 * * 4" # every Wednesday at 11:00
workflow_dispatch: # allows manual starts

jobs:
attempt-update:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
contents: write

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install elan
run: |
curl https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh -sSf | sh -s -- -y
echo "$HOME/.elan/bin" >> $GITHUB_PATH

- name: Update
run: lake update

- name: Check if anything was updated
uses: tj-actions/verify-changed-files@v18
id: check-update
with:
files: |
lean-toolchain
lake-manifest.json

- name: Try to build lean if something was updated
if: steps.check-update.outputs.files_changed == 'true'
id: build-lean
continue-on-error: true
run: |
lake exe cache get || true
lake build

- name: Run step only if nothing was updated
if: steps.check-update.outputs.files_changed == 'false'
run: |
echo "No update available"
echo "outcome=no-update" >> "$GITHUB_ENV"

- name: Run step only if the updated lean build was successful
id: step
if: steps.build-lean.outcome == 'success'
run: |
echo "Update available and build successful"
echo "outcome=update-success" >> "$GITHUB_ENV"

- name: Open PR if the updated lean build was successful
if: steps.build-lean.outcome == 'success'
uses: peter-evans/create-pull-request@v6
with:
title: "Updates available and ready to merge."
body: "To do: add useful details here..."
delete-branch: true
branch-suffix: random
branch: auto-update/patch

- name: Open issue if the updated lean build fails
if: steps.build-lean.outcome == 'failure'
run: |
echo "outcome=update-fail" >> "$GITHUB_ENV"
gh issue create \
--title "$TITLE" \
--label "$LABELS" \
--body "$BODY"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
TITLE: Updates available but manual intervention required
LABELS: bug
BODY: |
Run `lake update` and then investigate why this update causes the lean build to fail.
Files changed in update: ${{ steps.check-update.outputs.changed_files }}

# To do: Update action so that it will not create another issue until this present issue is closed.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If tracking issues is tricky, this is a good compromise since we can easily close the old one by hand

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A previous version had a bit of code which detected if there was still an issue produced from a prior run and then avoid creating a new issue. However it didn't work as expected and I failed to find my error. I'm sure it was just something stupid with the syntax. Another day I'll be able to find a way.

However I'm uncertain exactly what behaviour is preferred when it detects that an update is available but needs manual intervention. Options are:

  • Open new issue only if there is no open issue from a prior run
  • Close the prior issue and open a new issue
  • Do nothing with issues and send a message to the maintainers
  • Fail the workflow so notify the maintainers that there is something to do

We'll see what is best as we progress. I return to focus on completing the stuff in topology. It's been going well and soon should be done. Sebastien suggested to me to PR the alternate version of Cantor's theorem which we use into mathlib so that's also in progress.

Talk to you on Thursday!

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think "Fail the workflow so notify the maintainers that there is something to do" is already enough, at least I would see it in my github notifications anyway.

"Open new issue only if there is no open issue from a prior run" is a stronger signal than just a job failure, since in this case I would also get an email. I don't mind if it does not close the job though


- name: Show the outcome
run: echo "${{ env.outcome }}"
# To do: properly have an action with outputs