✨ Refresh artifact #403
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
# Crawl questions on GMAT Club and publish it to Github Pages as JSONs | |
# Fetch https://teddyos.github.io/gmat-database/index.json or https://teddyos.github.io/gmat-database/<question_id>.json to use it | |
name: Crawler | |
run-name: ${{ inputs.action && (inputs.action == 'crawl' && '🚀 Start crawling' || (inputs.action == 'edit-question' && format('📝 Edit question {0}', inputs.question_id) || format('🩸 Drop question {0}', inputs.question_id))) || '✨ Refresh artifact' }} | |
concurrency: gmat-database | |
on: | |
push: | |
branches: ["main"] | |
pull_request: | |
branches: ["main"] | |
schedule: | |
- cron: "0 0 * * *" | |
workflow_dispatch: | |
inputs: | |
action: | |
description: "Action to be executed" | |
required: true | |
default: "crawl" | |
type: choice | |
options: | |
- crawl | |
- edit-question | |
- drop-question | |
question_id: | |
description: "ID of the question to be edit or removed from the database (if the action to be executed is crawl/refresh please ignore)" | |
type: string | |
question_content: | |
description: "The new content of the question (if the action to be executed is edit-question)" | |
type: string | |
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | |
permissions: | |
contents: read | |
pages: write | |
deployments: write | |
id-token: write | |
jobs: | |
main: | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Setup repo | |
uses: actions/checkout@v3 | |
- name: Setup Deno | |
# uses: denoland/setup-deno@v1 | |
uses: denoland/setup-deno@9db7f66e8e16b5699a514448ce994936c63f0d54 | |
with: | |
deno-version: v1.x | |
- name: Download artifact | |
id: download-artifact | |
uses: dawidd6/action-download-artifact@v2 | |
continue-on-error: true | |
with: | |
name: github-pages | |
path: output | |
workflow_conclusion: success | |
- name: Extract pervious artifact | |
if: ${{ steps.download-artifact.outcome == 'success' }} | |
run: tar --skip-old-files -xf artifact.tar && rm artifact.tar | |
continue-on-error: ${{ inputs.action == 'crawl' }} | |
working-directory: output | |
- name: Download backup artifact | |
id: download-backup-artifact | |
if: ${{ steps.download-artifact.outcome == 'failure' }} | |
uses: dawidd6/action-download-artifact@v2 | |
continue-on-error: ${{ inputs.action == 'crawl' }} | |
with: | |
name: output-.* | |
name_is_regexp: true | |
path: output.bak | |
workflow_conclusion: success | |
- name: Rename artifact | |
if: ${{ steps.download-backup-artifact.outcome == 'success' }} | |
run: rm -rf ../output && mv "$(ls -d */)" ../output | |
working-directory: output.bak | |
- name: View current database | |
run: ls -R | |
working-directory: output | |
- name: Run linter | |
run: deno lint | |
- name: Run main | |
if: inputs.action == 'crawl' | |
run: deno run --allow-all ./main.ts >> $GITHUB_STEP_SUMMARY | |
- name: Run edit-question | |
if: inputs.action == 'edit-question' | |
run: deno run --allow-all ./edit-question.ts >> $GITHUB_STEP_SUMMARY | |
env: | |
QUESTION_ID: ${{ inputs.question_id }} | |
QUESTION_CONTENT: ${{ inputs.question_content }} | |
- name: Run drop-question | |
if: inputs.action == 'drop-question' | |
run: deno run --allow-all ./drop-question.ts >> $GITHUB_STEP_SUMMARY | |
env: | |
QUESTION_ID: ${{ inputs.question_id }} | |
# Must run in the same jobs otherwise previous output won't be kept | |
- name: Setup Pages | |
uses: actions/configure-pages@v2 | |
- name: Upload Github Pages artifact | |
uses: actions/upload-pages-artifact@v1 | |
with: | |
path: "./output" | |
- name: Upload backup artifact | |
uses: actions/upload-artifact@v3.1.2 | |
with: | |
name: output-${{ github.run_id }} | |
path: "./output/*" | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v1 |