From 0ca27ee8e262e925bc2f76c2127b537aadfa3771 Mon Sep 17 00:00:00 2001 From: Davide Marchegiani Date: Thu, 23 May 2024 16:39:45 +1000 Subject: [PATCH 1/7] Changed build/deploy workflow to use Work seamlessly with GitHub from the command line. USAGE gh [flags] CORE COMMANDS auth: Authenticate gh and git with GitHub browse: Open the repository in the browser codespace: Connect to and manage codespaces gist: Manage gists issue: Manage issues org: Manage organizations pr: Manage pull requests project: Work with GitHub Projects. release: Manage releases repo: Manage repositories GITHUB ACTIONS COMMANDS cache: Manage Github Actions caches run: View details about workflow runs workflow: View details about GitHub Actions workflows ALIAS COMMANDS co: Alias for "pr checkout" ADDITIONAL COMMANDS alias: Create command shortcuts api: Make an authenticated GitHub API request attestation: Work with artifact attestations completion: Generate shell completion scripts config: Manage configuration for gh extension: Manage gh extensions gpg-key: Manage GPG keys label: Manage labels ruleset: View info about repo rulesets search: Search for repositories, issues, and pull requests secret: Manage GitHub secrets ssh-key: Manage SSH keys status: Print information about relevant issues, pull requests, and notifications across repositories variable: Manage GitHub Actions variables HELP TOPICS actions: Learn about working with GitHub Actions environment: Environment variables that can be used with gh exit-codes: Exit codes used by gh formatting: Formatting options for JSON data exported from gh mintty: Information about using gh with MinTTY reference: A comprehensive reference of all gh commands FLAGS --help Show help for command --version Show gh version EXAMPLES $ gh issue create $ gh repo clone cli/cli $ gh pr checkout 321 LEARN MORE Use `gh --help` for more information about a command. Read the manual at https://cli.github.com/manual --- .github/workflows/deploy_to_github_pages.yml | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/.github/workflows/deploy_to_github_pages.yml b/.github/workflows/deploy_to_github_pages.yml index 7b04571fd..2cd93595f 100644 --- a/.github/workflows/deploy_to_github_pages.yml +++ b/.github/workflows/deploy_to_github_pages.yml @@ -159,14 +159,11 @@ jobs: retry 'git checkout development' 5 1 "Failed to checkout 'development' branch." retry 'mkdocs build -f mkdocs.yml -d ../website/development-website' 5 1 "Failed to build development website." echo "Build PR websites" - command="pr_list=\$(curl -s https://api.github.com/repos/${{github.repository}}/pulls?state=opened \ - | jq '.[] | select(.head.label!=\"${{ github.repository_owner }}:development\" and .head.label!=\"${{ github.repository_owner }}:main\")')" - retry "$command" 5 1 "Failed to fetch opened PRs." - pr_nums=($(jq '.number' <<< $pr_list)) + open_pr_nums_and_sha=$(gh pr list --json headRefOid,number --jq '.[]') + pr_nums=($(jq '.number' <<< "$open_pr_nums_and_sha")) + pr_sha=($(jq '.headRefOid' <<< "$open_pr_nums_and_sha")) if [[ -n $pr_nums ]]; then - echo "Found PR numbers: $(sed 's/\s/, /g' <<< ${pr_nums[@]})." - pr_sha=($(jq '.head.sha' <<< $pr_list)) - echo "pr_nums=$(sed 's/\s/,/g' <<< [${pr_nums[@]}])" >> "$GITHUB_OUTPUT" + echo "Found PR numbers: $(perl -pe 's/\s(?!$)/, /g' <<< ${pr_nums[@]})." for i in ${!pr_nums[@]}; do retry "git checkout ${pr_sha[i]}" 5 1 "Failed to checkout git hash '${pr_sha[i]}'." retry "mkdocs build -f mkdocs.yml -d ../website/pr-preview/pr-${pr_nums[i]}" 5 1 "Failed to build pr-${pr_nums[i]} website." @@ -174,7 +171,7 @@ jobs: else echo "No open PR found." fi - echo "Give the right file permissions" + echo "Set the right file permissions" chmod -c -R +rX ../website - name: Create artifact for deployment to GitHub Pages From c56e06215dc505cc5893542df38f6813f9446864 Mon Sep 17 00:00:00 2001 From: Davide Marchegiani Date: Thu, 23 May 2024 16:45:17 +1000 Subject: [PATCH 2/7] Set build/deploy workflow to use ADMIN_TOKEN from secrets --- .github/workflows/deploy_to_github_pages.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy_to_github_pages.yml b/.github/workflows/deploy_to_github_pages.yml index 2cd93595f..af382f28c 100644 --- a/.github/workflows/deploy_to_github_pages.yml +++ b/.github/workflows/deploy_to_github_pages.yml @@ -12,8 +12,9 @@ on: - closed env: TZ: Australia/Canberra -permissions: - pull-requests: write # to comment on PRs + GH_TOKEN: ${{ secrets.ADMIN_TOKEN }} +# permissions: +# pull-requests: write # to comment on PRs jobs: pr-preview-setup: From 99984f23cba5b9c6320182956139d604f9e8ee12 Mon Sep 17 00:00:00 2001 From: Davide Marchegiani Date: Thu, 23 May 2024 17:02:50 +1000 Subject: [PATCH 3/7] Test new token --- .github/workflows/deploy_to_github_pages.yml | 403 ++++++++++--------- 1 file changed, 202 insertions(+), 201 deletions(-) diff --git a/.github/workflows/deploy_to_github_pages.yml b/.github/workflows/deploy_to_github_pages.yml index af382f28c..a0f1aa637 100644 --- a/.github/workflows/deploy_to_github_pages.yml +++ b/.github/workflows/deploy_to_github_pages.yml @@ -31,6 +31,7 @@ jobs: if: ${{ github.event.pull_request.head.ref != 'development' && github.event.action != 'closed' }} uses: thollander/actions-comment-pull-request@v2.4.3 with: + GITHUB_TOKEN: ${{ env.GH_TOKEN }} comment_tag: pr-preview pr_number: ${{ github.event.number }} message: "\ @@ -101,204 +102,204 @@ jobs: ${{ env.DATE }} " - build: - # Cancel any previous build/deploy jobs that are still running (no need to build/deploy multiple times) - concurrency: - group: build-deploy - cancel-in-progress: true - runs-on: ubuntu-latest - outputs: - pr_nums: ${{ steps.build.outputs.pr_nums }} - url: ${{ steps.url.outputs.url }} - steps: - - name: Checkout - uses: actions/checkout@master - with: - ref: main - - - name: Get URL - id: url - run: echo "url=$(cat docs/CNAME)" >> "$GITHUB_OUTPUT" - - - name: Python setup - uses: actions/setup-python@v5 - with: - python-version: 3.9.x - - - name: Install dependencies - run: pip install -r requirements.txt - - # Build full website using main, development and open PRs head branches - # (excluding `development` and `main` as PR head branches) - - name: Build full website - id: build - shell: bash - run: | - retry() { - command="$1" - n_tries="$2" - wait="$3" - exit_msg="$4" - eval "$command" - until [ $? == 0 ]; do - if [ $i -eq $((n_tries - 1)) ]; then - echo "$exit_msg" - exit 1 - else - ((i++)) - fi - sleep $wait - eval "$command" - done - } - - git fetch --all - echo "Build main website" - retry "git checkout main" 5 1 "Failed to checkout 'main'." - retry 'mkdocs build -f mkdocs.yml -d ../website' 5 1 "Failed to build main website." - echo "Build development website" - retry 'git checkout development' 5 1 "Failed to checkout 'development' branch." - retry 'mkdocs build -f mkdocs.yml -d ../website/development-website' 5 1 "Failed to build development website." - echo "Build PR websites" - open_pr_nums_and_sha=$(gh pr list --json headRefOid,number --jq '.[]') - pr_nums=($(jq '.number' <<< "$open_pr_nums_and_sha")) - pr_sha=($(jq '.headRefOid' <<< "$open_pr_nums_and_sha")) - if [[ -n $pr_nums ]]; then - echo "Found PR numbers: $(perl -pe 's/\s(?!$)/, /g' <<< ${pr_nums[@]})." - for i in ${!pr_nums[@]}; do - retry "git checkout ${pr_sha[i]}" 5 1 "Failed to checkout git hash '${pr_sha[i]}'." - retry "mkdocs build -f mkdocs.yml -d ../website/pr-preview/pr-${pr_nums[i]}" 5 1 "Failed to build pr-${pr_nums[i]} website." - done - else - echo "No open PR found." - fi - echo "Set the right file permissions" - chmod -c -R +rX ../website - - - name: Create artifact for deployment to GitHub Pages - uses: actions/upload-pages-artifact@v2 - with: - path: ../website - - deploy: - needs: build - runs-on: ubuntu-latest - # Cancel any previous build/deploy jobs that are still running (no need to build/deploy multiple times) - concurrency: - group: build-deploy - cancel-in-progress: true - outputs: - success: ${{ steps.success.outputs.success }} - permissions: - pages: write # to deploy to Pages - id-token: write # to verify the deployment originates from an appropriate source - - steps: - - name: Deploy to GitHub Pages - uses: actions/deploy-pages@v2 - - - name: Output success status - id: success - run: | - echo "success=1" >> "$GITHUB_OUTPUT" - - # Set pr-preview URL - pr-preview: - needs: [build, deploy] - # If there are open PRs (whose head branch is neither `development` nor `main`), run this job - if: ${{ needs.build.outputs.pr_nums }} - runs-on: ubuntu-latest - # Run the same job for each of the open PRs found - strategy: - matrix: - pr_nums: ${{fromJson(needs.build.outputs.pr_nums)}} - steps: - - name: Get date - run: echo "DATE=$(date '+%Y-%m-%d %H:%M %Z')" >> $GITHUB_ENV - - - name: Set pr-preview URL - if: ${{github.event.action != 'closed'}} - uses: thollander/actions-comment-pull-request@v2.4.3 - with: - comment_tag: pr-preview - pr_number: ${{ matrix.pr_nums }} - message: "\ - PR Preview - - :---: - - 🚀 Deployed preview to - https://${{ needs.build.outputs.url }}/pr-preview/pr-${{ matrix.pr_nums }} - - ${{ env.DATE }} - " - # Add development URL - development-preview: - needs: [build, deploy] - # If there are open PRs (whose head branch is neither `development` nor `main`), run this job - if: ${{ github.event.pull_request.head.ref == 'development' }} - runs-on: ubuntu-latest - steps: - - name: Get date - run: echo "DATE=$(date '+%Y-%m-%d %H:%M %Z')" >> $GITHUB_ENV - - - name: Add development-preview URL - if: ${{github.event.action != 'closed'}} - uses: thollander/actions-comment-pull-request@v2.4.3 - with: - comment_tag: pr-preview - pr_number: ${{ github.event.number }} - message: "\ - Development website preview - - :---: - - 🚀 Development website deployed to - https://${{ needs.build.outputs.url }}/development-website - - ${{ env.DATE }} - " - - # Change preview message if deployment fails - failed-preview: - needs: deploy - # If the action failed (but was not cancelled) and was fired because of a pull request (not closed) - if: ${{ always() && '!cancelled()' && github.event_name == 'pull_request' && github.event.action != 'closed' && needs.deploy.outputs.success != '1' }} - runs-on: ubuntu-latest - steps: - - name: Get date - run: echo "DATE=$(date '+%Y-%m-%d %H:%M %Z')" >> $GITHUB_ENV - - - name: Change development-preview message - if: ${{ github.event.pull_request.head.ref == 'development' }} - uses: thollander/actions-comment-pull-request@v2.4.3 - with: - comment_tag: pr-preview - pr_number: ${{ github.event.number }} - message: "\ - Development website preview - - :---: - - ⚠️ There was an error in the deployment of the development website. - For more information, please check the [Actions](https://github.com/${{github.repository}}/actions) tab. - - ${{ env.DATE }} - " - - - name: Change pr-preview message - if: ${{ github.event.pull_request.head.ref != 'development' }} - uses: thollander/actions-comment-pull-request@v2.4.3 - with: - comment_tag: pr-preview - pr_number: ${{ github.event.number }} - message: "\ - PR preview - - :---: - - ⚠️ There was an error in the pr-preview deployment. - For more information, please check the [Actions](https://github.com/${{github.repository}}/actions) tab. - - ${{ env.DATE }} - " + # build: + # # Cancel any previous build/deploy jobs that are still running (no need to build/deploy multiple times) + # concurrency: + # group: build-deploy + # cancel-in-progress: true + # runs-on: ubuntu-latest + # outputs: + # pr_nums: ${{ steps.build.outputs.pr_nums }} + # url: ${{ steps.url.outputs.url }} + # steps: + # - name: Checkout + # uses: actions/checkout@master + # with: + # ref: main + + # - name: Get URL + # id: url + # run: echo "url=$(cat docs/CNAME)" >> "$GITHUB_OUTPUT" + + # - name: Python setup + # uses: actions/setup-python@v5 + # with: + # python-version: 3.9.x + + # - name: Install dependencies + # run: pip install -r requirements.txt + + # # Build full website using main, development and open PRs head branches + # # (excluding `development` and `main` as PR head branches) + # - name: Build full website + # id: build + # shell: bash + # run: | + # retry() { + # command="$1" + # n_tries="$2" + # wait="$3" + # exit_msg="$4" + # eval "$command" + # until [ $? == 0 ]; do + # if [ $i -eq $((n_tries - 1)) ]; then + # echo "$exit_msg" + # exit 1 + # else + # ((i++)) + # fi + # sleep $wait + # eval "$command" + # done + # } + + # git fetch --all + # echo "Build main website" + # retry "git checkout main" 5 1 "Failed to checkout 'main'." + # retry 'mkdocs build -f mkdocs.yml -d ../website' 5 1 "Failed to build main website." + # echo "Build development website" + # retry 'git checkout development' 5 1 "Failed to checkout 'development' branch." + # retry 'mkdocs build -f mkdocs.yml -d ../website/development-website' 5 1 "Failed to build development website." + # echo "Build PR websites" + # open_pr_nums_and_sha=$(gh pr list --json headRefOid,number --jq '.[]') + # pr_nums=($(jq '.number' <<< "$open_pr_nums_and_sha")) + # pr_sha=($(jq '.headRefOid' <<< "$open_pr_nums_and_sha")) + # if [[ -n $pr_nums ]]; then + # echo "Found PR numbers: $(perl -pe 's/\s(?!$)/, /g' <<< ${pr_nums[@]})." + # for i in ${!pr_nums[@]}; do + # retry "git checkout ${pr_sha[i]}" 5 1 "Failed to checkout git hash '${pr_sha[i]}'." + # retry "mkdocs build -f mkdocs.yml -d ../website/pr-preview/pr-${pr_nums[i]}" 5 1 "Failed to build pr-${pr_nums[i]} website." + # done + # else + # echo "No open PR found." + # fi + # echo "Set the right file permissions" + # chmod -c -R +rX ../website + + # - name: Create artifact for deployment to GitHub Pages + # uses: actions/upload-pages-artifact@v2 + # with: + # path: ../website + + # deploy: + # needs: build + # runs-on: ubuntu-latest + # # Cancel any previous build/deploy jobs that are still running (no need to build/deploy multiple times) + # concurrency: + # group: build-deploy + # cancel-in-progress: true + # outputs: + # success: ${{ steps.success.outputs.success }} + # permissions: + # pages: write # to deploy to Pages + # id-token: write # to verify the deployment originates from an appropriate source + + # steps: + # - name: Deploy to GitHub Pages + # uses: actions/deploy-pages@v2 + + # - name: Output success status + # id: success + # run: | + # echo "success=1" >> "$GITHUB_OUTPUT" + + # # Set pr-preview URL + # pr-preview: + # needs: [build, deploy] + # # If there are open PRs (whose head branch is neither `development` nor `main`), run this job + # if: ${{ needs.build.outputs.pr_nums }} + # runs-on: ubuntu-latest + # # Run the same job for each of the open PRs found + # strategy: + # matrix: + # pr_nums: ${{fromJson(needs.build.outputs.pr_nums)}} + # steps: + # - name: Get date + # run: echo "DATE=$(date '+%Y-%m-%d %H:%M %Z')" >> $GITHUB_ENV + + # - name: Set pr-preview URL + # if: ${{github.event.action != 'closed'}} + # uses: thollander/actions-comment-pull-request@v2.4.3 + # with: + # comment_tag: pr-preview + # pr_number: ${{ matrix.pr_nums }} + # message: "\ + # PR Preview + + # :---: + + # 🚀 Deployed preview to + # https://${{ needs.build.outputs.url }}/pr-preview/pr-${{ matrix.pr_nums }} + + # ${{ env.DATE }} + # " + # # Add development URL + # development-preview: + # needs: [build, deploy] + # # If there are open PRs (whose head branch is neither `development` nor `main`), run this job + # if: ${{ github.event.pull_request.head.ref == 'development' }} + # runs-on: ubuntu-latest + # steps: + # - name: Get date + # run: echo "DATE=$(date '+%Y-%m-%d %H:%M %Z')" >> $GITHUB_ENV + + # - name: Add development-preview URL + # if: ${{github.event.action != 'closed'}} + # uses: thollander/actions-comment-pull-request@v2.4.3 + # with: + # comment_tag: pr-preview + # pr_number: ${{ github.event.number }} + # message: "\ + # Development website preview + + # :---: + + # 🚀 Development website deployed to + # https://${{ needs.build.outputs.url }}/development-website + + # ${{ env.DATE }} + # " + + # # Change preview message if deployment fails + # failed-preview: + # needs: deploy + # # If the action failed (but was not cancelled) and was fired because of a pull request (not closed) + # if: ${{ always() && '!cancelled()' && github.event_name == 'pull_request' && github.event.action != 'closed' && needs.deploy.outputs.success != '1' }} + # runs-on: ubuntu-latest + # steps: + # - name: Get date + # run: echo "DATE=$(date '+%Y-%m-%d %H:%M %Z')" >> $GITHUB_ENV + + # - name: Change development-preview message + # if: ${{ github.event.pull_request.head.ref == 'development' }} + # uses: thollander/actions-comment-pull-request@v2.4.3 + # with: + # comment_tag: pr-preview + # pr_number: ${{ github.event.number }} + # message: "\ + # Development website preview + + # :---: + + # ⚠️ There was an error in the deployment of the development website. + # For more information, please check the [Actions](https://github.com/${{github.repository}}/actions) tab. + + # ${{ env.DATE }} + # " + + # - name: Change pr-preview message + # if: ${{ github.event.pull_request.head.ref != 'development' }} + # uses: thollander/actions-comment-pull-request@v2.4.3 + # with: + # comment_tag: pr-preview + # pr_number: ${{ github.event.number }} + # message: "\ + # PR preview + + # :---: + + # ⚠️ There was an error in the pr-preview deployment. + # For more information, please check the [Actions](https://github.com/${{github.repository}}/actions) tab. + + # ${{ env.DATE }} + # " From 2e56fcc15572f5102215ff80e70f4a6363024918 Mon Sep 17 00:00:00 2001 From: Davide Marchegiani Date: Thu, 23 May 2024 17:47:10 +1000 Subject: [PATCH 4/7] Added admin token to build/deploy workflow --- .github/workflows/deploy_to_github_pages.yml | 418 ++++++++++--------- 1 file changed, 213 insertions(+), 205 deletions(-) diff --git a/.github/workflows/deploy_to_github_pages.yml b/.github/workflows/deploy_to_github_pages.yml index a0f1aa637..d73e06ecd 100644 --- a/.github/workflows/deploy_to_github_pages.yml +++ b/.github/workflows/deploy_to_github_pages.yml @@ -11,10 +11,8 @@ on: - synchronize - closed env: - TZ: Australia/Canberra GH_TOKEN: ${{ secrets.ADMIN_TOKEN }} -# permissions: -# pull-requests: write # to comment on PRs + TZ: Australia/Canberra jobs: pr-preview-setup: @@ -31,7 +29,7 @@ jobs: if: ${{ github.event.pull_request.head.ref != 'development' && github.event.action != 'closed' }} uses: thollander/actions-comment-pull-request@v2.4.3 with: - GITHUB_TOKEN: ${{ env.GH_TOKEN }} + GITHUB_TOKEN: ${{ secrets.ADMIN_TOKEN }} comment_tag: pr-preview pr_number: ${{ github.event.number }} message: "\ @@ -53,6 +51,7 @@ jobs: if: ${{ github.event.pull_request.head.ref == 'development' && github.event.action != 'closed' }} uses: thollander/actions-comment-pull-request@v2.4.3 with: + GITHUB_TOKEN: ${{ secrets.ADMIN_TOKEN }} comment_tag: pr-preview pr_number: ${{ github.event.number }} message: "\ @@ -73,6 +72,7 @@ jobs: if: ${{github.event.action == 'closed' && github.event.pull_request.head.ref != 'development' }} uses: thollander/actions-comment-pull-request@v2.4.3 with: + GITHUB_TOKEN: ${{ secrets.ADMIN_TOKEN }} comment_tag: pr-preview pr_number: ${{ github.event.number }} message: "\ @@ -90,6 +90,7 @@ jobs: if: ${{github.event.action == 'closed' && github.event.pull_request.head.ref == 'development' }} uses: thollander/actions-comment-pull-request@v2.4.3 with: + GITHUB_TOKEN: ${{ secrets.ADMIN_TOKEN }} comment_tag: pr-preview pr_number: ${{ github.event.number }} message: "\ @@ -102,204 +103,211 @@ jobs: ${{ env.DATE }} " - # build: - # # Cancel any previous build/deploy jobs that are still running (no need to build/deploy multiple times) - # concurrency: - # group: build-deploy - # cancel-in-progress: true - # runs-on: ubuntu-latest - # outputs: - # pr_nums: ${{ steps.build.outputs.pr_nums }} - # url: ${{ steps.url.outputs.url }} - # steps: - # - name: Checkout - # uses: actions/checkout@master - # with: - # ref: main - - # - name: Get URL - # id: url - # run: echo "url=$(cat docs/CNAME)" >> "$GITHUB_OUTPUT" - - # - name: Python setup - # uses: actions/setup-python@v5 - # with: - # python-version: 3.9.x - - # - name: Install dependencies - # run: pip install -r requirements.txt - - # # Build full website using main, development and open PRs head branches - # # (excluding `development` and `main` as PR head branches) - # - name: Build full website - # id: build - # shell: bash - # run: | - # retry() { - # command="$1" - # n_tries="$2" - # wait="$3" - # exit_msg="$4" - # eval "$command" - # until [ $? == 0 ]; do - # if [ $i -eq $((n_tries - 1)) ]; then - # echo "$exit_msg" - # exit 1 - # else - # ((i++)) - # fi - # sleep $wait - # eval "$command" - # done - # } - - # git fetch --all - # echo "Build main website" - # retry "git checkout main" 5 1 "Failed to checkout 'main'." - # retry 'mkdocs build -f mkdocs.yml -d ../website' 5 1 "Failed to build main website." - # echo "Build development website" - # retry 'git checkout development' 5 1 "Failed to checkout 'development' branch." - # retry 'mkdocs build -f mkdocs.yml -d ../website/development-website' 5 1 "Failed to build development website." - # echo "Build PR websites" - # open_pr_nums_and_sha=$(gh pr list --json headRefOid,number --jq '.[]') - # pr_nums=($(jq '.number' <<< "$open_pr_nums_and_sha")) - # pr_sha=($(jq '.headRefOid' <<< "$open_pr_nums_and_sha")) - # if [[ -n $pr_nums ]]; then - # echo "Found PR numbers: $(perl -pe 's/\s(?!$)/, /g' <<< ${pr_nums[@]})." - # for i in ${!pr_nums[@]}; do - # retry "git checkout ${pr_sha[i]}" 5 1 "Failed to checkout git hash '${pr_sha[i]}'." - # retry "mkdocs build -f mkdocs.yml -d ../website/pr-preview/pr-${pr_nums[i]}" 5 1 "Failed to build pr-${pr_nums[i]} website." - # done - # else - # echo "No open PR found." - # fi - # echo "Set the right file permissions" - # chmod -c -R +rX ../website - - # - name: Create artifact for deployment to GitHub Pages - # uses: actions/upload-pages-artifact@v2 - # with: - # path: ../website - - # deploy: - # needs: build - # runs-on: ubuntu-latest - # # Cancel any previous build/deploy jobs that are still running (no need to build/deploy multiple times) - # concurrency: - # group: build-deploy - # cancel-in-progress: true - # outputs: - # success: ${{ steps.success.outputs.success }} - # permissions: - # pages: write # to deploy to Pages - # id-token: write # to verify the deployment originates from an appropriate source - - # steps: - # - name: Deploy to GitHub Pages - # uses: actions/deploy-pages@v2 - - # - name: Output success status - # id: success - # run: | - # echo "success=1" >> "$GITHUB_OUTPUT" - - # # Set pr-preview URL - # pr-preview: - # needs: [build, deploy] - # # If there are open PRs (whose head branch is neither `development` nor `main`), run this job - # if: ${{ needs.build.outputs.pr_nums }} - # runs-on: ubuntu-latest - # # Run the same job for each of the open PRs found - # strategy: - # matrix: - # pr_nums: ${{fromJson(needs.build.outputs.pr_nums)}} - # steps: - # - name: Get date - # run: echo "DATE=$(date '+%Y-%m-%d %H:%M %Z')" >> $GITHUB_ENV - - # - name: Set pr-preview URL - # if: ${{github.event.action != 'closed'}} - # uses: thollander/actions-comment-pull-request@v2.4.3 - # with: - # comment_tag: pr-preview - # pr_number: ${{ matrix.pr_nums }} - # message: "\ - # PR Preview - - # :---: - - # 🚀 Deployed preview to - # https://${{ needs.build.outputs.url }}/pr-preview/pr-${{ matrix.pr_nums }} - - # ${{ env.DATE }} - # " - # # Add development URL - # development-preview: - # needs: [build, deploy] - # # If there are open PRs (whose head branch is neither `development` nor `main`), run this job - # if: ${{ github.event.pull_request.head.ref == 'development' }} - # runs-on: ubuntu-latest - # steps: - # - name: Get date - # run: echo "DATE=$(date '+%Y-%m-%d %H:%M %Z')" >> $GITHUB_ENV - - # - name: Add development-preview URL - # if: ${{github.event.action != 'closed'}} - # uses: thollander/actions-comment-pull-request@v2.4.3 - # with: - # comment_tag: pr-preview - # pr_number: ${{ github.event.number }} - # message: "\ - # Development website preview - - # :---: - - # 🚀 Development website deployed to - # https://${{ needs.build.outputs.url }}/development-website - - # ${{ env.DATE }} - # " - - # # Change preview message if deployment fails - # failed-preview: - # needs: deploy - # # If the action failed (but was not cancelled) and was fired because of a pull request (not closed) - # if: ${{ always() && '!cancelled()' && github.event_name == 'pull_request' && github.event.action != 'closed' && needs.deploy.outputs.success != '1' }} - # runs-on: ubuntu-latest - # steps: - # - name: Get date - # run: echo "DATE=$(date '+%Y-%m-%d %H:%M %Z')" >> $GITHUB_ENV - - # - name: Change development-preview message - # if: ${{ github.event.pull_request.head.ref == 'development' }} - # uses: thollander/actions-comment-pull-request@v2.4.3 - # with: - # comment_tag: pr-preview - # pr_number: ${{ github.event.number }} - # message: "\ - # Development website preview - - # :---: - - # ⚠️ There was an error in the deployment of the development website. - # For more information, please check the [Actions](https://github.com/${{github.repository}}/actions) tab. - - # ${{ env.DATE }} - # " - - # - name: Change pr-preview message - # if: ${{ github.event.pull_request.head.ref != 'development' }} - # uses: thollander/actions-comment-pull-request@v2.4.3 - # with: - # comment_tag: pr-preview - # pr_number: ${{ github.event.number }} - # message: "\ - # PR preview - - # :---: - - # ⚠️ There was an error in the pr-preview deployment. - # For more information, please check the [Actions](https://github.com/${{github.repository}}/actions) tab. - - # ${{ env.DATE }} - # " + build: + # Cancel any previous build/deploy jobs that are still running (no need to build/deploy multiple times) + concurrency: + group: build-deploy + cancel-in-progress: true + runs-on: ubuntu-latest + outputs: + pr_nums: ${{ steps.build.outputs.pr_nums }} + url: ${{ steps.url.outputs.url }} + steps: + - name: Checkout + uses: actions/checkout@master + with: + token: ${{ secrets.ADMIN_TOKEN }} + ref: main + + - name: Get URL + id: url + run: echo "url=$(cat docs/CNAME)" >> "$GITHUB_OUTPUT" + + - name: Python setup + uses: actions/setup-python@v5 + with: + python-version: 3.9.x + + - name: Install dependencies + run: pip install -r requirements.txt + + # Build full website using main, development and open PRs head branches + # (excluding `development` and `main` as PR head branches) + - name: Build full website + id: build + shell: bash + run: | + retry() { + command="$1" + n_tries="$2" + wait="$3" + exit_msg="$4" + eval "$command" + until [ $? == 0 ]; do + if [ $i -eq $((n_tries - 1)) ]; then + echo "$exit_msg" + exit 1 + else + ((i++)) + fi + sleep $wait + eval "$command" + done + } + + git fetch --all + echo "Build main website" + retry "git checkout main" 5 1 "Failed to checkout 'main'." + retry 'mkdocs build -f mkdocs.yml -d ../website' 5 1 "Failed to build main website." + echo "Build development website" + retry 'git checkout development' 5 1 "Failed to checkout 'development' branch." + retry 'mkdocs build -f mkdocs.yml -d ../website/development-website' 5 1 "Failed to build development website." + echo "Build PR websites" + open_pr_nums_and_sha=$(gh pr list --json headRefOid,number --jq '.[]') + pr_nums=($(jq '.number' <<< "$open_pr_nums_and_sha")) + pr_sha=($(jq '.headRefOid' <<< "$open_pr_nums_and_sha")) + if [[ -n $pr_nums ]]; then + echo "Found PR numbers: $(perl -pe 's/\s(?!$)/, /g' <<< ${pr_nums[@]})." + for i in ${!pr_nums[@]}; do + retry "git checkout ${pr_sha[i]}" 5 1 "Failed to checkout git hash '${pr_sha[i]}'." + retry "mkdocs build -f mkdocs.yml -d ../website/pr-preview/pr-${pr_nums[i]}" 5 1 "Failed to build pr-${pr_nums[i]} website." + done + else + echo "No open PR found." + fi + echo "Set the right file permissions" + chmod -c -R +rX ../website + + - name: Create artifact for deployment to GitHub Pages + uses: actions/upload-pages-artifact@v2 + with: + path: ../website + + deploy: + needs: build + runs-on: ubuntu-latest + # Cancel any previous build/deploy jobs that are still running (no need to build/deploy multiple times) + concurrency: + group: build-deploy + cancel-in-progress: true + outputs: + success: ${{ steps.success.outputs.success }} + permissions: + pages: write # to deploy to Pages + id-token: write # to verify the deployment originates from an appropriate source + + steps: + - name: Deploy to GitHub Pages + uses: actions/deploy-pages@v2 + with: + token: ${{ secrets.ADMIN_TOKEN }} + + - name: Output success status + id: success + run: | + echo "success=1" >> "$GITHUB_OUTPUT" + + # Set pr-preview URL + pr-preview: + needs: [build, deploy] + # If there are open PRs (whose head branch is neither `development` nor `main`), run this job + if: ${{ needs.build.outputs.pr_nums }} + runs-on: ubuntu-latest + # Run the same job for each of the open PRs found + strategy: + matrix: + pr_nums: ${{fromJson(needs.build.outputs.pr_nums)}} + steps: + - name: Get date + run: echo "DATE=$(date '+%Y-%m-%d %H:%M %Z')" >> $GITHUB_ENV + + - name: Set pr-preview URL + if: ${{github.event.action != 'closed'}} + uses: thollander/actions-comment-pull-request@v2.4.3 + with: + GITHUB_TOKEN: ${{ secrets.ADMIN_TOKEN }} + comment_tag: pr-preview + pr_number: ${{ matrix.pr_nums }} + message: "\ + PR Preview + + :---: + + 🚀 Deployed preview to + https://${{ needs.build.outputs.url }}/pr-preview/pr-${{ matrix.pr_nums }} + + ${{ env.DATE }} + " + # Add development URL + development-preview: + needs: [build, deploy] + # If there are open PRs (whose head branch is neither `development` nor `main`), run this job + if: ${{ github.event.pull_request.head.ref == 'development' }} + runs-on: ubuntu-latest + steps: + - name: Get date + run: echo "DATE=$(date '+%Y-%m-%d %H:%M %Z')" >> $GITHUB_ENV + + - name: Add development-preview URL + if: ${{github.event.action != 'closed'}} + uses: thollander/actions-comment-pull-request@v2.4.3 + with: + GITHUB_TOKEN: ${{ secrets.ADMIN_TOKEN }} + comment_tag: pr-preview + pr_number: ${{ github.event.number }} + message: "\ + Development website preview + + :---: + + 🚀 Development website deployed to + https://${{ needs.build.outputs.url }}/development-website + + ${{ env.DATE }} + " + + # Change preview message if deployment fails + failed-preview: + needs: deploy + # If the action failed (but was not cancelled) and was fired because of a pull request (not closed) + if: ${{ always() && '!cancelled()' && github.event_name == 'pull_request' && github.event.action != 'closed' && needs.deploy.outputs.success != '1' }} + runs-on: ubuntu-latest + steps: + - name: Get date + run: echo "DATE=$(date '+%Y-%m-%d %H:%M %Z')" >> $GITHUB_ENV + + - name: Change development-preview message + if: ${{ github.event.pull_request.head.ref == 'development' }} + uses: thollander/actions-comment-pull-request@v2.4.3 + with: + GITHUB_TOKEN: ${{ secrets.ADMIN_TOKEN }} + comment_tag: pr-preview + pr_number: ${{ github.event.number }} + message: "\ + Development website preview + + :---: + + ⚠️ There was an error in the deployment of the development website. + For more information, please check the [Actions](https://github.com/${{github.repository}}/actions) tab. + + ${{ env.DATE }} + " + + - name: Change pr-preview message + if: ${{ github.event.pull_request.head.ref != 'development' }} + uses: thollander/actions-comment-pull-request@v2.4.3 + with: + GITHUB_TOKEN: ${{ secrets.ADMIN_TOKEN }} + comment_tag: pr-preview + pr_number: ${{ github.event.number }} + message: "\ + PR preview + + :---: + + ⚠️ There was an error in the pr-preview deployment. + For more information, please check the [Actions](https://github.com/${{github.repository}}/actions) tab. + + ${{ env.DATE }} + " From ae919f2731355de91e3bcf216e92fdd300545fe1 Mon Sep 17 00:00:00 2001 From: Davide Marchegiani Date: Thu, 23 May 2024 18:40:16 +1000 Subject: [PATCH 5/7] Updated query for 'jq' in build/deploy workflow to exclude from the preview PRs having headRef as 'main' or 'development'. --- .github/workflows/deploy_to_github_pages.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy_to_github_pages.yml b/.github/workflows/deploy_to_github_pages.yml index d73e06ecd..c035a889a 100644 --- a/.github/workflows/deploy_to_github_pages.yml +++ b/.github/workflows/deploy_to_github_pages.yml @@ -90,7 +90,7 @@ jobs: if: ${{github.event.action == 'closed' && github.event.pull_request.head.ref == 'development' }} uses: thollander/actions-comment-pull-request@v2.4.3 with: - GITHUB_TOKEN: ${{ secrets.ADMIN_TOKEN }} + # GITHUB_TOKEN: ${{ secrets.ADMIN_TOKEN }} comment_tag: pr-preview pr_number: ${{ github.event.number }} message: "\ @@ -163,9 +163,9 @@ jobs: retry 'git checkout development' 5 1 "Failed to checkout 'development' branch." retry 'mkdocs build -f mkdocs.yml -d ../website/development-website' 5 1 "Failed to build development website." echo "Build PR websites" - open_pr_nums_and_sha=$(gh pr list --json headRefOid,number --jq '.[]') - pr_nums=($(jq '.number' <<< "$open_pr_nums_and_sha")) - pr_sha=($(jq '.headRefOid' <<< "$open_pr_nums_and_sha")) + open_pr_info=$(gh pr list --json headRefOid,number,headRefName --jq '.[] | select(.headRefName!="development" and .headRefName!="main")') + pr_nums=($(jq '.number' <<< "$open_pr_info")) + pr_sha=($(jq '.headRefOid' <<< "$open_pr_info")) if [[ -n $pr_nums ]]; then echo "Found PR numbers: $(perl -pe 's/\s(?!$)/, /g' <<< ${pr_nums[@]})." for i in ${!pr_nums[@]}; do From ae30b24c327859455dc9abab1077f181abf9e470 Mon Sep 17 00:00:00 2001 From: Davide Marchegiani Date: Thu, 23 May 2024 19:06:33 +1000 Subject: [PATCH 6/7] Added pr_nums as output to allow pr-preview job to trigger correctly --- .github/workflows/deploy_to_github_pages.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deploy_to_github_pages.yml b/.github/workflows/deploy_to_github_pages.yml index c035a889a..3e5f2087c 100644 --- a/.github/workflows/deploy_to_github_pages.yml +++ b/.github/workflows/deploy_to_github_pages.yml @@ -168,6 +168,7 @@ jobs: pr_sha=($(jq '.headRefOid' <<< "$open_pr_info")) if [[ -n $pr_nums ]]; then echo "Found PR numbers: $(perl -pe 's/\s(?!$)/, /g' <<< ${pr_nums[@]})." + echo "pr_nums=[$(perl -pe 's/\s(?!$)/,/g' <<< ${pr_nums[@]})]" >> "$GITHUB_OUTPUT" for i in ${!pr_nums[@]}; do retry "git checkout ${pr_sha[i]}" 5 1 "Failed to checkout git hash '${pr_sha[i]}'." retry "mkdocs build -f mkdocs.yml -d ../website/pr-preview/pr-${pr_nums[i]}" 5 1 "Failed to build pr-${pr_nums[i]} website." From aea38810cbf488ea8566bc3c990c8ee088ec50c3 Mon Sep 17 00:00:00 2001 From: Davide Marchegiani Date: Thu, 23 May 2024 19:43:06 +1000 Subject: [PATCH 7/7] Restructured the workflow to separate cases for PR-preview, development preview, open and closed PRs for the preview setups. TEST --- .github/workflows/deploy_to_github_pages.yml | 527 +++++++++---------- 1 file changed, 246 insertions(+), 281 deletions(-) diff --git a/.github/workflows/deploy_to_github_pages.yml b/.github/workflows/deploy_to_github_pages.yml index 3e5f2087c..9bf08bf5e 100644 --- a/.github/workflows/deploy_to_github_pages.yml +++ b/.github/workflows/deploy_to_github_pages.yml @@ -20,295 +20,260 @@ jobs: if: ${{ github.event_name == 'pull_request' }} runs-on: ubuntu-latest steps: - - name: Get date - run: echo "DATE=$(date '+%Y-%m-%d %H:%M %Z')" >> $GITHUB_ENV - - - name: Setup pr-preview - # If the PR is not from the development branch and is new (or has been reopened), - # setup the message that will get updated with the URL after deployment - if: ${{ github.event.pull_request.head.ref != 'development' && github.event.action != 'closed' }} - uses: thollander/actions-comment-pull-request@v2.4.3 - with: - GITHUB_TOKEN: ${{ secrets.ADMIN_TOKEN }} - comment_tag: pr-preview - pr_number: ${{ github.event.number }} - message: "\ - PR preview - - :---: - - 🛫 Deployment still ongoing.
- Preview URL will be available at the end of the deployment. - - For more information, please check the [Actions](https://github.com/${{ github.repository }}/actions) tab. - - ${{ env.DATE }} - " - - - name: Setup development preview - # If the PR is from the development branch and is new (or has been reopened), - # setup the message that will get updated with the URL after deployment - if: ${{ github.event.pull_request.head.ref == 'development' && github.event.action != 'closed' }} - uses: thollander/actions-comment-pull-request@v2.4.3 - with: - GITHUB_TOKEN: ${{ secrets.ADMIN_TOKEN }} - comment_tag: pr-preview - pr_number: ${{ github.event.number }} - message: "\ - Development website preview - - :---: - - 🛫 Deployment still ongoing.
- Preview URL will be available at the end of the deployment. - - For more information, please check the [Actions](https://github.com/${{github.repository}}/actions) tab. - - ${{ env.DATE }} - " - - # If the PR is closed, remove the pr-preview URL - - name: Remove pr-preview URL link - if: ${{github.event.action == 'closed' && github.event.pull_request.head.ref != 'development' }} - uses: thollander/actions-comment-pull-request@v2.4.3 - with: - GITHUB_TOKEN: ${{ secrets.ADMIN_TOKEN }} - comment_tag: pr-preview - pr_number: ${{ github.event.number }} - message: "\ - PR Preview - - :---: - - 🛬 Link removed because the pull request was closed. - - ${{ env.DATE }} - " - - # If the PR is closed, remove the development URL - - name: Remove development URL - if: ${{github.event.action == 'closed' && github.event.pull_request.head.ref == 'development' }} - uses: thollander/actions-comment-pull-request@v2.4.3 - with: - # GITHUB_TOKEN: ${{ secrets.ADMIN_TOKEN }} - comment_tag: pr-preview - pr_number: ${{ github.event.number }} - message: "\ - Development website preview - - :---: - - 🛬 Preview removed because the pull request was closed. - - ${{ env.DATE }} - " - - build: - # Cancel any previous build/deploy jobs that are still running (no need to build/deploy multiple times) - concurrency: - group: build-deploy - cancel-in-progress: true - runs-on: ubuntu-latest - outputs: - pr_nums: ${{ steps.build.outputs.pr_nums }} - url: ${{ steps.url.outputs.url }} - steps: - - name: Checkout - uses: actions/checkout@master - with: - token: ${{ secrets.ADMIN_TOKEN }} - ref: main - - - name: Get URL - id: url - run: echo "url=$(cat docs/CNAME)" >> "$GITHUB_OUTPUT" - - - name: Python setup - uses: actions/setup-python@v5 - with: - python-version: 3.9.x - - - name: Install dependencies - run: pip install -r requirements.txt - - # Build full website using main, development and open PRs head branches - # (excluding `development` and `main` as PR head branches) - - name: Build full website - id: build - shell: bash + - name: Set up PR preview title + # Set up infos for PR (new, updated or reopened branch not having a head as 'development' or 'main' branch) + if: ${{ github.event.pull_request.head.ref != 'development' && github.event.pull_request.head.ref != 'main' }} run: | - retry() { - command="$1" - n_tries="$2" - wait="$3" - exit_msg="$4" - eval "$command" - until [ $? == 0 ]; do - if [ $i -eq $((n_tries - 1)) ]; then - echo "$exit_msg" - exit 1 - else - ((i++)) - fi - sleep $wait - eval "$command" - done - } - - git fetch --all - echo "Build main website" - retry "git checkout main" 5 1 "Failed to checkout 'main'." - retry 'mkdocs build -f mkdocs.yml -d ../website' 5 1 "Failed to build main website." - echo "Build development website" - retry 'git checkout development' 5 1 "Failed to checkout 'development' branch." - retry 'mkdocs build -f mkdocs.yml -d ../website/development-website' 5 1 "Failed to build development website." - echo "Build PR websites" - open_pr_info=$(gh pr list --json headRefOid,number,headRefName --jq '.[] | select(.headRefName!="development" and .headRefName!="main")') - pr_nums=($(jq '.number' <<< "$open_pr_info")) - pr_sha=($(jq '.headRefOid' <<< "$open_pr_info")) - if [[ -n $pr_nums ]]; then - echo "Found PR numbers: $(perl -pe 's/\s(?!$)/, /g' <<< ${pr_nums[@]})." - echo "pr_nums=[$(perl -pe 's/\s(?!$)/,/g' <<< ${pr_nums[@]})]" >> "$GITHUB_OUTPUT" - for i in ${!pr_nums[@]}; do - retry "git checkout ${pr_sha[i]}" 5 1 "Failed to checkout git hash '${pr_sha[i]}'." - retry "mkdocs build -f mkdocs.yml -d ../website/pr-preview/pr-${pr_nums[i]}" 5 1 "Failed to build pr-${pr_nums[i]} website." - done - else - echo "No open PR found." - fi - echo "Set the right file permissions" - chmod -c -R +rX ../website - - - name: Create artifact for deployment to GitHub Pages - uses: actions/upload-pages-artifact@v2 - with: - path: ../website - - deploy: - needs: build - runs-on: ubuntu-latest - # Cancel any previous build/deploy jobs that are still running (no need to build/deploy multiple times) - concurrency: - group: build-deploy - cancel-in-progress: true - outputs: - success: ${{ steps.success.outputs.success }} - permissions: - pages: write # to deploy to Pages - id-token: write # to verify the deployment originates from an appropriate source - - steps: - - name: Deploy to GitHub Pages - uses: actions/deploy-pages@v2 - with: - token: ${{ secrets.ADMIN_TOKEN }} - - - name: Output success status - id: success + echo 'TITLE=PR preview' >> $GITHUB_ENV + + - name: Set up development preview title + # Set up infos for PR (new, updated or reopened branch not having a head as 'development' or 'main' branch) + if: ${{ github.event.pull_request.head.ref == 'development' }} run: | - echo "success=1" >> "$GITHUB_OUTPUT" - - # Set pr-preview URL - pr-preview: - needs: [build, deploy] - # If there are open PRs (whose head branch is neither `development` nor `main`), run this job - if: ${{ needs.build.outputs.pr_nums }} - runs-on: ubuntu-latest - # Run the same job for each of the open PRs found - strategy: - matrix: - pr_nums: ${{fromJson(needs.build.outputs.pr_nums)}} - steps: - - name: Get date - run: echo "DATE=$(date '+%Y-%m-%d %H:%M %Z')" >> $GITHUB_ENV - - - name: Set pr-preview URL - if: ${{github.event.action != 'closed'}} - uses: thollander/actions-comment-pull-request@v2.4.3 - with: - GITHUB_TOKEN: ${{ secrets.ADMIN_TOKEN }} - comment_tag: pr-preview - pr_number: ${{ matrix.pr_nums }} - message: "\ - PR Preview - - :---: - - 🚀 Deployed preview to - https://${{ needs.build.outputs.url }}/pr-preview/pr-${{ matrix.pr_nums }} - - ${{ env.DATE }} - " - # Add development URL - development-preview: - needs: [build, deploy] - # If there are open PRs (whose head branch is neither `development` nor `main`), run this job - if: ${{ github.event.pull_request.head.ref == 'development' }} - runs-on: ubuntu-latest - steps: - - name: Get date - run: echo "DATE=$(date '+%Y-%m-%d %H:%M %Z')" >> $GITHUB_ENV - - - name: Add development-preview URL - if: ${{github.event.action != 'closed'}} - uses: thollander/actions-comment-pull-request@v2.4.3 - with: - GITHUB_TOKEN: ${{ secrets.ADMIN_TOKEN }} - comment_tag: pr-preview - pr_number: ${{ github.event.number }} - message: "\ - Development website preview - - :---: - - 🚀 Development website deployed to - https://${{ needs.build.outputs.url }}/development-website + echo 'TITLE=Development website preview' >> $GITHUB_ENV - ${{ env.DATE }} - " - - # Change preview message if deployment fails - failed-preview: - needs: deploy - # If the action failed (but was not cancelled) and was fired because of a pull request (not closed) - if: ${{ always() && '!cancelled()' && github.event_name == 'pull_request' && github.event.action != 'closed' && needs.deploy.outputs.success != '1' }} - runs-on: ubuntu-latest - steps: - name: Get date run: echo "DATE=$(date '+%Y-%m-%d %H:%M %Z')" >> $GITHUB_ENV - - name: Change development-preview message - if: ${{ github.event.pull_request.head.ref == 'development' }} - uses: thollander/actions-comment-pull-request@v2.4.3 - with: - GITHUB_TOKEN: ${{ secrets.ADMIN_TOKEN }} - comment_tag: pr-preview - pr_number: ${{ github.event.number }} - message: "\ - Development website preview - - :---: - - ⚠️ There was an error in the deployment of the development website. - For more information, please check the [Actions](https://github.com/${{github.repository}}/actions) tab. - - ${{ env.DATE }} - " - - - name: Change pr-preview message - if: ${{ github.event.pull_request.head.ref != 'development' }} + - name: Set up open PR message + if: ${{ github.event.action != 'closed' }} + run: | + MULTI_LINES_TEXT="${{ env.TITLE }}\n + :---:\n + 🛫 Deployment still ongoing.
+ Preview URL will be available at the end of the deployment.\n + For more information, please check the [Actions](https://github.com/${{ github.repository }}/actions) tab.\n + ${{ env.DATE }}" + + echo "MSG<> $GITHUB_ENV + echo -e $MULTI_LINES_TEXT >> $GITHUB_ENV + echo "EOF" >> $GITHUB_ENV + + - name: Set up closed PR message + if: ${{ github.event.action == 'closed' }} + run: | + MULTI_LINES_TEXT="${{ env.TITLE }}\n + :---:\n + 🛬 Preview link removed because the pull request was closed." + + echo "MSG<> $GITHUB_ENV + echo -e $MULTI_LINES_TEXT >> $GITHUB_ENV + echo "EOF" >> $GITHUB_ENV + + - name: Set preview uses: thollander/actions-comment-pull-request@v2.4.3 with: GITHUB_TOKEN: ${{ secrets.ADMIN_TOKEN }} comment_tag: pr-preview pr_number: ${{ github.event.number }} - message: "\ - PR preview - - :---: - - ⚠️ There was an error in the pr-preview deployment. - For more information, please check the [Actions](https://github.com/${{github.repository}}/actions) tab. - - ${{ env.DATE }} - " + message: ${{ env.MSG }} + + # build: + # # Cancel any previous build/deploy jobs that are still running (no need to build/deploy multiple times) + # concurrency: + # group: build-deploy + # cancel-in-progress: true + # runs-on: ubuntu-latest + # outputs: + # pr_nums: ${{ steps.build.outputs.pr_nums }} + # url: ${{ steps.url.outputs.url }} + # steps: + # - name: Checkout + # uses: actions/checkout@master + # with: + # token: ${{ secrets.ADMIN_TOKEN }} + # ref: main + + # - name: Get URL + # id: url + # run: echo "url=$(cat docs/CNAME)" >> "$GITHUB_OUTPUT" + + # - name: Python setup + # uses: actions/setup-python@v5 + # with: + # python-version: 3.9.x + + # - name: Install dependencies + # run: pip install -r requirements.txt + + # # Build full website using main, development and open PRs head branches + # # (excluding `development` and `main` as PR head branches) + # - name: Build full website + # id: build + # shell: bash + # run: | + # retry() { + # command="$1" + # n_tries="$2" + # wait="$3" + # exit_msg="$4" + # eval "$command" + # until [ $? == 0 ]; do + # if [ $i -eq $((n_tries - 1)) ]; then + # echo "$exit_msg" + # exit 1 + # else + # ((i++)) + # fi + # sleep $wait + # eval "$command" + # done + # } + + # git fetch --all + # echo "Build main website" + # retry "git checkout main" 5 1 "Failed to checkout 'main'." + # retry 'mkdocs build -f mkdocs.yml -d ../website' 5 1 "Failed to build main website." + # echo "Build development website" + # retry 'git checkout development' 5 1 "Failed to checkout 'development' branch." + # retry 'mkdocs build -f mkdocs.yml -d ../website/development-website' 5 1 "Failed to build development website." + # echo "Build PR websites" + # open_pr_info=$(gh pr list --json headRefOid,number,headRefName --jq '.[] | select(.headRefName!="development" and .headRefName!="main")') + # pr_nums=($(jq '.number' <<< "$open_pr_info")) + # pr_sha=($(jq '.headRefOid' <<< "$open_pr_info")) + # if [[ -n $pr_nums ]]; then + # echo "Found PR numbers: $(perl -pe 's/\s(?!$)/, /g' <<< ${pr_nums[@]})." + # echo "pr_nums=[$(perl -pe 's/\s(?!$)/,/g' <<< ${pr_nums[@]})]" >> "$GITHUB_OUTPUT" + # for i in ${!pr_nums[@]}; do + # retry "git checkout ${pr_sha[i]}" 5 1 "Failed to checkout git hash '${pr_sha[i]}'." + # retry "mkdocs build -f mkdocs.yml -d ../website/pr-preview/pr-${pr_nums[i]}" 5 1 "Failed to build pr-${pr_nums[i]} website." + # done + # else + # echo "No open PR found." + # fi + # echo "Set the right file permissions" + # chmod -c -R +rX ../website + + # - name: Create artifact for deployment to GitHub Pages + # uses: actions/upload-pages-artifact@v2 + # with: + # path: ../website + + # deploy: + # needs: build + # runs-on: ubuntu-latest + # # Cancel any previous build/deploy jobs that are still running (no need to build/deploy multiple times) + # concurrency: + # group: build-deploy + # cancel-in-progress: true + # outputs: + # success: ${{ steps.success.outputs.success }} + # permissions: + # pages: write # to deploy to Pages + # id-token: write # to verify the deployment originates from an appropriate source + + # steps: + # - name: Deploy to GitHub Pages + # uses: actions/deploy-pages@v2 + # with: + # token: ${{ secrets.ADMIN_TOKEN }} + + # - name: Output success status + # id: success + # run: | + # echo "success=1" >> "$GITHUB_OUTPUT" + + # # Set pr-preview URL + # pr-preview: + # needs: [build, deploy] + # # If there are open PRs (whose head branch is neither `development` nor `main`), run this job + # if: ${{ needs.build.outputs.pr_nums }} + # runs-on: ubuntu-latest + # # Run the same job for each of the open PRs found + # strategy: + # matrix: + # pr_nums: ${{fromJson(needs.build.outputs.pr_nums)}} + # steps: + # - name: Get date + # run: echo "DATE=$(date '+%Y-%m-%d %H:%M %Z')" >> $GITHUB_ENV + + # - name: Set pr-preview URL + # if: ${{github.event.action != 'closed'}} + # uses: thollander/actions-comment-pull-request@v2.4.3 + # with: + # GITHUB_TOKEN: ${{ secrets.ADMIN_TOKEN }} + # comment_tag: pr-preview + # pr_number: ${{ matrix.pr_nums }} + # message: "\ + # PR Preview + + # :---: + + # 🚀 Deployed preview to + # https://${{ needs.build.outputs.url }}/pr-preview/pr-${{ matrix.pr_nums }} + + # ${{ env.DATE }} + # " + # # Add development URL + # development-preview: + # needs: [build, deploy] + # # If there are open PRs (whose head branch is neither `development` nor `main`), run this job + # if: ${{ github.event.pull_request.head.ref == 'development' }} + # runs-on: ubuntu-latest + # steps: + # - name: Get date + # run: echo "DATE=$(date '+%Y-%m-%d %H:%M %Z')" >> $GITHUB_ENV + + # - name: Add development-preview URL + # if: ${{github.event.action != 'closed'}} + # uses: thollander/actions-comment-pull-request@v2.4.3 + # with: + # GITHUB_TOKEN: ${{ secrets.ADMIN_TOKEN }} + # comment_tag: pr-preview + # pr_number: ${{ github.event.number }} + # message: "\ + # Development website preview + + # :---: + + # 🚀 Development website deployed to + # https://${{ needs.build.outputs.url }}/development-website + + # ${{ env.DATE }} + # " + + # # Change preview message if deployment fails + # failed-preview: + # needs: deploy + # # If the action failed (but was not cancelled) and was fired because of a pull request (not closed) + # if: ${{ always() && '!cancelled()' && github.event_name == 'pull_request' && github.event.action != 'closed' && needs.deploy.outputs.success != '1' }} + # runs-on: ubuntu-latest + # steps: + # - name: Get date + # run: echo "DATE=$(date '+%Y-%m-%d %H:%M %Z')" >> $GITHUB_ENV + + # - name: Change development-preview message + # if: ${{ github.event.pull_request.head.ref == 'development' }} + # uses: thollander/actions-comment-pull-request@v2.4.3 + # with: + # GITHUB_TOKEN: ${{ secrets.ADMIN_TOKEN }} + # comment_tag: pr-preview + # pr_number: ${{ github.event.number }} + # message: "\ + # Development website preview + + # :---: + + # ⚠️ There was an error in the deployment of the development website. + # For more information, please check the [Actions](https://github.com/${{github.repository}}/actions) tab. + + # ${{ env.DATE }} + # " + + # - name: Change pr-preview message + # if: ${{ github.event.pull_request.head.ref != 'development' }} + # uses: thollander/actions-comment-pull-request@v2.4.3 + # with: + # GITHUB_TOKEN: ${{ secrets.ADMIN_TOKEN }} + # comment_tag: pr-preview + # pr_number: ${{ github.event.number }} + # message: "\ + # PR preview + + # :---: + + # ⚠️ There was an error in the pr-preview deployment. + # For more information, please check the [Actions](https://github.com/${{github.repository}}/actions) tab. + + # ${{ env.DATE }} + # "