From b7d983fa0ea2de041a2d6b9bafab828759e09cf5 Mon Sep 17 00:00:00 2001 From: Penelope Yong Date: Wed, 27 Nov 2024 13:02:52 +0000 Subject: [PATCH] Fix GHA stuff (#563) * Make version check script more explicit Instead of calling ]up, it calls ]add Turing@, which more closely matches our intentions * Fix version check GHA to not always show green tick * Separate preview + remove-preview workflows * Don't run preview on closed PRs --- .github/workflows/preview.yml | 37 ++++------------------------ .github/workflows/remove_preview.yml | 31 +++++++++++++++++++++++ .github/workflows/version_check.jl | 7 +++++- .github/workflows/version_check.yml | 5 ++-- 4 files changed, 44 insertions(+), 36 deletions(-) create mode 100644 .github/workflows/remove_preview.yml diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 15f35b84c..b33926c08 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -5,11 +5,14 @@ on: types: - opened - synchronize - - closed concurrency: group: docs +permissions: + contents: write + pull-requests: write + jobs: build-and-preview: if: github.event.action == 'opened' || github.event.action == 'synchronize' @@ -70,12 +73,7 @@ jobs: commit-message: Deploy preview for PR ${{ github.event.pull_request.number }} token: ${{ secrets.GITHUB_TOKEN }} - comment-preview-url: - needs: build-and-preview - if: needs.build-and-preview.result == 'success' - runs-on: ubuntu-latest - steps: - - name: Comment Preview URL + - name: Comment preview URL uses: thollander/actions-comment-pull-request@v2 with: message: | @@ -83,28 +81,3 @@ jobs: Preview the changes: https://turinglang.org/docs/pr-previews/${{ github.event.pull_request.number }} Please avoid using the search feature and navigation bar in PR previews! comment_tag: preview-url-comment - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - delete-preview-directory: - if: github.event.action == 'closed' || github.event.pull_request.merged == true - runs-on: ubuntu-latest - steps: - - name: Checkout gh-pages branch - uses: actions/checkout@v4 - with: - ref: gh-pages - - - name: Remove PR Preview Directory - run: | - PR_NUMBER=${{ github.event.pull_request.number }} - PREVIEW_DIR="pr-previews/${PR_NUMBER}" - git config --global user.name "github-actions[bot]" - git config --global user.email "github-actions[bot]@users.noreply.github.com" - git pull origin gh-pages - rm -rf ${PREVIEW_DIR} - git add . - git commit -m "Remove preview for merged PR #${PR_NUMBER}" - git push - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/remove_preview.yml b/.github/workflows/remove_preview.yml new file mode 100644 index 000000000..40f67e619 --- /dev/null +++ b/.github/workflows/remove_preview.yml @@ -0,0 +1,31 @@ +name: Remove PR previews + +on: + pull_request_target: + types: + - closed + +permissions: + contents: write + +jobs: + delete-preview-directory: + if: github.event.action == 'closed' || github.event.pull_request.merged == true + runs-on: ubuntu-latest + steps: + - name: Checkout gh-pages branch + uses: actions/checkout@v4 + with: + ref: gh-pages + + - name: Remove PR Preview Directory + run: | + PR_NUMBER=${{ github.event.pull_request.number }} + PREVIEW_DIR="pr-previews/${PR_NUMBER}" + git config --global user.name "github-actions[bot]" + git config --global user.email "github-actions[bot]@users.noreply.github.com" + git pull origin gh-pages + rm -rf ${PREVIEW_DIR} + git add . + git commit -m "Remove preview for merged PR #${PR_NUMBER}" + git push diff --git a/.github/workflows/version_check.jl b/.github/workflows/version_check.jl index f3ae7381d..f2277fb39 100644 --- a/.github/workflows/version_check.jl +++ b/.github/workflows/version_check.jl @@ -107,7 +107,12 @@ if ENV["TARGET_IS_MASTER"] == "true" println("$(MANIFEST_TOML_PATH) is out of date; updating") old_env = Pkg.project().path Pkg.activate(".") - Pkg.update() + try + Pkg.add(name="Turing", version=latest_version) + catch e + # If the Manifest couldn't be updated, the error will be shown later + println(e) + end # Check if versions match now, error if not Pkg.activate(old_env) manifest_toml = TOML.parsefile(MANIFEST_TOML_PATH) diff --git a/.github/workflows/version_check.yml b/.github/workflows/version_check.yml index a8842d705..a434623ea 100644 --- a/.github/workflows/version_check.yml +++ b/.github/workflows/version_check.yml @@ -51,12 +51,11 @@ jobs: - name: Check version consistency id: version_check - continue-on-error: true run: julia --color=yes .github/workflows/version_check.jl - name: Create a PR with suggested changes id: create_pr - if: steps.version_check.outcome == 'failure' && env.TARGET_IS_MASTER && (! env.IS_PR_FROM_FORK) + if: always() && steps.version_check.outcome == 'failure' && env.TARGET_IS_MASTER && (! env.IS_PR_FROM_FORK) uses: peter-evans/create-pull-request@v6 with: base: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref_name }} @@ -66,7 +65,7 @@ jobs: title: "Update Turing.jl version to match latest release" - name: Comment on PR about suggested changes (if PR was made) - if: github.event_name == 'pull_request' && steps.create_pr.outputs.pull-request-operation == 'created' + if: always() && github.event_name == 'pull_request' && steps.create_pr.outputs.pull-request-operation == 'created' uses: thollander/actions-comment-pull-request@v2 with: message: |