From 502c54ad0cb86048746567fce49add253132daee Mon Sep 17 00:00:00 2001 From: Brian Rose Date: Tue, 4 Oct 2022 15:19:24 -0400 Subject: [PATCH] Try calling resusable preview action --- .github/workflows/deploy-preview.yaml | 137 ------------------ .github/workflows/trigger-book-build.yaml | 8 +- .github/workflows/trigger-deploy-preview.yaml | 12 ++ .github/workflows/trigger-link-check.yaml | 13 ++ 4 files changed, 26 insertions(+), 144 deletions(-) delete mode 100644 .github/workflows/deploy-preview.yaml create mode 100644 .github/workflows/trigger-deploy-preview.yaml create mode 100644 .github/workflows/trigger-link-check.yaml diff --git a/.github/workflows/deploy-preview.yaml b/.github/workflows/deploy-preview.yaml deleted file mode 100644 index ee8462d77..000000000 --- a/.github/workflows/deploy-preview.yaml +++ /dev/null @@ -1,137 +0,0 @@ -name: deploy-preview -on: - workflow_run: - workflows: - - trigger-book-build - types: - - requested - - completed - -jobs: - deploy: - runs-on: ubuntu-latest - defaults: - run: - shell: bash -l {0} - steps: - - uses: actions/checkout@v3 - - name: Fetch Repo Name - id: repo-name - run: echo "::set-output name=value::$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')" # just the repo name, not owner - - - name: Set message value - run: | - echo "comment_message=👋 Thanks for opening this PR! The Cookbook will be automatically built with [GitHub Actions](https://github.com/features/actions). To see the status of your deployment, click below." >> $GITHUB_ENV - - - name: Find Pull Request - uses: actions/github-script@v6 - id: find-pull-request - with: - script: | - let pullRequestNumber = '' - let pullRequestHeadSHA = '' - core.info('Finding pull request...') - const pullRequests = await github.rest.pulls.list({owner: context.repo.owner, repo: context.repo.repo}) - for (let pullRequest of pullRequests.data) { - if(pullRequest.head.sha === context.payload.workflow_run.head_commit.id) { - pullRequestHeadSHA = pullRequest.head.sha - pullRequestNumber = pullRequest.number - break - } - } - core.setOutput('number', pullRequestNumber) - core.setOutput('sha', pullRequestHeadSHA) - if(pullRequestNumber === '') { - core.info( - `No pull request associated with git commit SHA: ${context.payload.workflow_run.head_commit.id}` - ) - } - else{ - core.info(`Found pull request ${pullRequestNumber}, with head sha: ${pullRequestHeadSHA}`) - } - - - name: Find preview comment - uses: peter-evans/find-comment@v2 - if: steps.find-pull-request.outputs.number != '' - id: fc - with: - issue-number: '${{ steps.find-pull-request.outputs.number }}' - comment-author: 'github-actions[bot]' - body-includes: '${{ env.comment_message }}' - - - name: Create preview comment - if: | - github.event.workflow_run.conclusion != 'success' - && steps.find-pull-request.outputs.number != '' - && steps.fc.outputs.comment-id == '' - uses: peter-evans/create-or-update-comment@v2 - with: - issue-number: ${{ steps.find-pull-request.outputs.number }} - body: | - ${{ env.comment_message }} - 🔍 Git commit SHA: ${{ steps.find-pull-request.outputs.sha }} - ✅ Deployment Preview URL: In Progress - - - name: Update preview comment - if: | - github.event.workflow_run.conclusion != 'success' - && steps.find-pull-request.outputs.number != '' - && steps.fc.outputs.comment-id != '' - uses: peter-evans/create-or-update-comment@v2 - with: - comment-id: ${{ steps.fc.outputs.comment-id }} - edit-mode: replace - body: | - ${{ env.comment_message }} - 🔍 Git commit SHA: ${{ steps.find-pull-request.outputs.sha }} - ✅ Deployment Preview URL: In Progress - - - name: Download Artifact Book - if: | - github.event.workflow_run.conclusion == 'success' - && steps.find-pull-request.outputs.number != '' - && steps.fc.outputs.comment-id != '' - uses: dawidd6/action-download-artifact@v2.23.0 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - workflow: build-book.yaml - run_id: ${{ github.event.workflow_run.id }} - name: book-zip-${{ steps.find-pull-request.outputs.number }} - - - name: Unzip the book - if: | - github.event.workflow_run.conclusion == 'success' - && steps.find-pull-request.outputs.number != '' - && steps.fc.outputs.comment-id != '' - run: | - rm -rf _build/html - unzip book.zip - rm -f book.zip - - # Push the book's HTML to github-pages - # This will be published at /_preview/PRnumber/ relative to the main site - - name: Deploy to GitHub pages - if: | - github.event.workflow_run.conclusion == 'success' - && steps.find-pull-request.outputs.number != '' - && steps.fc.outputs.comment-id != '' - uses: peaceiris/actions-gh-pages@v3.8.0 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: _build/html - enable_jekyll: false - destination_dir: _preview/${{ steps.find-pull-request.outputs.number }} - - - name: Finalize preview comment - if: | - github.event.workflow_run.conclusion == 'success' - && steps.find-pull-request.outputs.number != '' - && steps.fc.outputs.comment-id != '' - uses: peter-evans/create-or-update-comment@v2 - with: - comment-id: ${{ steps.fc.outputs.comment-id }} - edit-mode: replace - body: | - ${{ env.comment_message }} - 🔍 Git commit SHA: ${{ steps.find-pull-request.outputs.sha }} - ✅ Deployment Preview URL: https://${{ github.repository_owner }}.github.io/${{ steps.repo-name.outputs.value }}/_preview/${{ steps.find-pull-request.outputs.number }} diff --git a/.github/workflows/trigger-book-build.yaml b/.github/workflows/trigger-book-build.yaml index f33a14c23..f7b755784 100644 --- a/.github/workflows/trigger-book-build.yaml +++ b/.github/workflows/trigger-book-build.yaml @@ -10,10 +10,4 @@ jobs: environment_file: environment.yml path_to_notebooks: ./ use_cached_environment: 'true' # This is default, not strickly needed. Set to 'false' to always build a new environment - link-check: - uses: ProjectPythiaCookbooks/cookbook-actions/.github/workflows/link-checker.yaml@main - with: - environment_name: cookbook-dev - environment_file: environment.yml - path_to_notebooks: ./ - use_cached_environment: 'true' + \ No newline at end of file diff --git a/.github/workflows/trigger-deploy-preview.yaml b/.github/workflows/trigger-deploy-preview.yaml new file mode 100644 index 000000000..e7bcae34a --- /dev/null +++ b/.github/workflows/trigger-deploy-preview.yaml @@ -0,0 +1,12 @@ +name: trigger-deploy-preview +on: + workflow_run: + workflows: + - trigger-book-build + types: + - requested + - completed + +jobs: + deploy: + uses: ProjectPythiaCookbooks/cookbook-actions/.github/workflows/deploy-preview.yaml@main \ No newline at end of file diff --git a/.github/workflows/trigger-link-check.yaml b/.github/workflows/trigger-link-check.yaml new file mode 100644 index 000000000..fc772b4dd --- /dev/null +++ b/.github/workflows/trigger-link-check.yaml @@ -0,0 +1,13 @@ +name: trigger-link-check +on: + pull_request: + +jobs: + link-check: + uses: ProjectPythiaCookbooks/cookbook-actions/.github/workflows/link-checker.yaml@main + with: + environment_name: cookbook-dev + environment_file: environment.yml + path_to_notebooks: ./ + use_cached_environment: 'true' + \ No newline at end of file