Attempt to fix workflow_dispatch #12
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: Validate Activity List (and release if on master) | |
on: | |
pull_request: | |
branches: [ master ] | |
push: | |
branches: [ master ] | |
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | |
permissions: | |
contents: write | |
pages: write | |
id-token: write | |
jobs: | |
validate: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out repository | |
uses: actions/checkout@v2 | |
- name: Install Node.js 20.x | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '20.x' | |
- name: Install dependencies | |
run: npm install @openactive/skos ajv | |
- name: Validate activity-list.jsonld | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const Ajv = require('ajv'); | |
const fs = require('fs'); | |
const skos = require('@openactive/skos'); | |
var schemafile = "./schema/activity-list.schema.json"; | |
var rawfile = "./data/activity-list.jsonld"; | |
let schema = JSON.parse(fs.readFileSync(schemafile)); | |
let data = JSON.parse(fs.readFileSync(rawfile)); | |
var ajv = new Ajv({ allErrors: 'true', verbose: 'true' }); | |
var validate = ajv.compile(schema); | |
var is_valid = validate(data); | |
// Try to load into SKOS.js (will throw on failure) | |
var scheme = new skos.ConceptScheme(data); | |
if(is_valid){ | |
console.log("activity-list.jsonld passed validation"); | |
} else { | |
const errorMessage = "activity-list.jsonld failed validation" | |
console.log(`${errorMessage}\n=======\n`); | |
console.log(validate.errors); | |
throw new Error(errorMessage); | |
} | |
release: | |
needs: validate | |
runs-on: ubuntu-latest | |
if: ${{ !contains(toJSON(github.event.commits.*.message), '[no-release]') && github.ref == 'refs/heads/master' }} | |
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. | |
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. | |
concurrency: | |
group: "pages" | |
cancel-in-progress: false | |
# Deploy to the github-pages environment | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
steps: | |
- name: Check out repository | |
uses: actions/checkout@v2 | |
- name: Get Current Time | |
id: timestamp | |
uses: nanzm/[email protected] | |
with: | |
format: 'YYYY-MM-DD_HH-mm-ss' | |
- name: Render PR body | |
id: fetch_pr | |
uses: actions/github-script@v7 | |
with: | |
result-encoding: string | |
script: | | |
const { data: pulls } = await github.rest.pulls.list({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
state: 'closed', | |
head: context.sha | |
}); | |
const pr = pulls.find(pr => pr.merge_commit_sha === context.sha); | |
if (pr) { | |
return `${pr.body || ''}\n\nAssociated PR: #${pr.number}`; | |
} else { | |
console.log('No associated PR found; skipping release creation.'); | |
return ''; | |
} | |
- name: Copy redirect index.html to data folder for deployment | |
if: ${{ steps.fetch_pr.outputs.result != '' }} | |
# .gitattributes is included in the /data/ directory of the gh-pages branch, so that index.html is not included in the release zip based on the same | |
run: | | |
cp ./gh-pages/index.html ./data/ | |
- name: Setup Pages | |
if: ${{ steps.fetch_pr.outputs.result != ''}} | |
uses: actions/configure-pages@v4 | |
- name: Upload artifact | |
if: ${{ steps.fetch_pr.outputs.result != ''}} | |
uses: actions/upload-pages-artifact@v3 | |
with: | |
# Upload only /data/ directory | |
path: './data/' | |
- name: Deploy artifact to GitHub Pages | |
if: ${{ steps.fetch_pr.outputs.result != ''}} | |
id: deployment | |
uses: actions/deploy-pages@v4 | |
- name: Create Release | |
if: ${{ steps.fetch_pr.outputs.result != '' }} | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: v${{ steps.timestamp.outputs.time }} | |
release_name: Release v${{ steps.timestamp.outputs.time }} | |
body: ${{ steps.fetch_pr.outputs.result }} | |
draft: false | |
prerelease: false |