Deploy Jekyll with GitHub Pages dependencies preinstalled #80
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
name: Deploy Jekyll with GitHub Pages dependencies preinstalled | |
on: | |
workflow_run: | |
workflows: ["Receive_PR"] | |
types: | |
- completed | |
workflow_dispatch: | |
permissions: | |
contents: write | |
pages: write | |
id-token: write | |
pull-requests: write | |
concurrency: | |
group: "pages" | |
cancel-in-progress: true | |
jobs: | |
Extract_Receive_Pr: | |
runs-on: ubuntu-latest | |
if: > | |
(github.event.workflow_run.event == 'pull_request' || github.event.workflow_run.event == 'push') && | |
github.event.workflow_run.conclusion == 'success' | |
steps: | |
- name: 'Download artifact github pages' | |
uses: actions/github-script@v6 | |
id: artifactgh-pages | |
with: | |
script: | | |
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
run_id: ${{github.event.workflow_run.id }}, | |
}); | |
var matchArtifact = artifacts.data.artifacts.filter((artifact) => { | |
return artifact.name == "github-pages" | |
})[0]; | |
var download = await github.rest.actions.downloadArtifact({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
artifact_id: matchArtifact.id, | |
archive_format: 'zip', | |
}); | |
var fs = require('fs'); | |
fs.writeFileSync('${{github.workspace}}/github-pages.zip', Buffer.from(download.data)); | |
return matchArtifact.id | |
- run: | | |
unzip github-pages.zip | |
mkdir web-site | |
tar -xvf artifact.tar -C web-site/ | |
- name: Deploy | |
uses: peaceiris/actions-gh-pages@v3 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: web-site | |
CommentPr: | |
runs-on: ubuntu-latest | |
if: > | |
github.event.workflow_run.event == 'pull_request' && | |
github.event.workflow_run.conclusion == 'success' | |
steps: | |
- name: get PR number | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
run_id: ${{github.event.workflow_run.id }}, | |
}); | |
var matchArtifact = artifacts.data.artifacts.filter((artifact) => { | |
return artifact.name == "pr_number" | |
})[0]; | |
var download = await github.rest.actions.downloadArtifact({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
artifact_id: matchArtifact.id, | |
archive_format: 'zip', | |
}); | |
var fs = require('fs'); | |
fs.writeFileSync('${{github.workspace}}/pr_number.zip', Buffer.from(download.data)); | |
return matchArtifact.id | |
- name: get Pr number | |
id: prnumber | |
run: | | |
unzip pr_number.zip | |
echo "number=$(cat pr_number.txt)" >> $GITHUB_OUTPUT | |
- name: Post address | |
uses: actions/github-script@v6 | |
if: ${{ success()}} | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: "The web-site is built. It will be available, after a few minutes, here: https://cgal.github.io/cgal-web/index.html", | |
issue_number: ${{steps.prnumber.outputs.number}} | |
}); | |
- name: Post error | |
uses: actions/github-script@v6 | |
if: ${{ failure()}} | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: "There was an error while building the web-site", | |
issue_number: ${{steps.prnumber.outputs.number}} | |
}); |