Refactor yaml format #1
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: Check PR | |
on: | |
pull_request: | |
branches: | |
- main | |
permissions: | |
pull-requests: write | |
contents: read | |
jobs: | |
preview: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/setup-node@v2 | |
with: | |
node-version: '20' | |
- name: Install surge | |
run: npm --global install surge | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ github.head_ref }} | |
- name: Check keys of the projects.yaml file | |
run: | | |
python3 -m venv .venv | |
source .venv/bin/activate | |
pip3 install PyYAML | |
python3 check_keys.py >> summary.txt | |
- name: Post comment with summary | |
if: always() | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const fs = require('fs'); | |
const summary = fs.readFileSync("summary.txt", 'utf8'); | |
github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.payload.pull_request.number, | |
body: summary | |
}); | |
- name: Generate HTML site and README.md | |
run: | | |
python3 -m venv .venv | |
source .venv/bin/activate | |
pip3 install lxml | |
python3 init_site.py | |
rm website/base.html | |
python3 init_readme.py | |
- name: Package artifacts | |
run: tar -czf package.tar.gz ./website/images ./website/index.html ./website/filter.js ./website/styles.css | |
- name: Upload package as artifact | |
id: artifact-upload-step | |
uses: actions/upload-artifact@v4 | |
with: | |
name: package-${{ github.run_number }} | |
path: package.tar.gz | |
retention-days: 14 | |
overwrite: true | |
- name: Deploy PR preview | |
run: | | |
surge ./website ${{ github.repository_owner}}-oss-collection-preview-${{ github.event.number }}.surge.sh --token ${{ secrets.SURGE_TOKEN }} | |
- name: Post preview URL and artifact URL as a comment on PR | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const fs = require('fs'); | |
const summary = fs.readFileSync("summary.txt", 'utf8'); | |
const artifactUrl = `# 💾 Generated site \n Artifact URL: ${{ steps.artifact-upload-step.outputs.artifact-url }}`; | |
const previewUrl = `# 🚀 PR preview \n Site URL: <https://${{ github.repository_owner}}-oss-collection-preview-${{ github.event.number }}.surge.sh>` | |
const bodyContent = `${previewUrl}\n${artifactUrl}`; | |
github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.payload.pull_request.number, | |
body: bodyContent | |
}); | |
- name: Post README.md as comment for preview | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const fs = require('fs'); | |
const readme = fs.readFileSync("README.md", 'utf8'); | |
const summary = `# 📄 Preview of generated README.md \n <details><summary>Preview</summary> \n \n ${readme} </details>` | |
github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.payload.pull_request.number, | |
body: summary | |
}); | |