Skip to content

Commit

Permalink
Bind auto-publish jobs to actual spec updates (w3c#825)
Browse files Browse the repository at this point in the history
Each time an update was made to any of the specs in the repository, all 16
specs got re-published because the auto-publish workflow did not know what was
changed. This took time for no good reason.

The [`paths` filter](https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#onpushpull_requestpull_request_targetpathspaths-ignore)
allows to run a workflow conditionally. Unfortunately, it only applies at the
workflow level (and cannot be set at the job level within a workflow in
particular).

This adds an auto-publish workflow template and a companion script to generate
auto-publish workflows for each and every spec in the repository, that only run
when needed, meaning only when the spec source did change. The script only
needs to run once in a while when new specs get added or when the workflows
need to change.

The new auto-publish workflows created by the script replace the previous
`auto-publish.yml` workflow.

Note: The `auto-publish.yml` workflow still had a `BUILD_FAIL_ON: nothing`
property, which was meant to be a temporary measure and should no longer be
needed:
w3c@adfb63c
This update switches back to `BUILD_FAIL_ON: warning`.

This is the same approach as that done for w3c/encrypted-media:
w3c/encrypted-media@cefbd73
  • Loading branch information
tidoust authored Sep 10, 2024
1 parent dd799db commit 6fd01eb
Show file tree
Hide file tree
Showing 19 changed files with 990 additions and 124 deletions.
48 changes: 48 additions & 0 deletions .github/auto-publish-template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
######################################################################
# This is the template used to generate auto-publication workflows for
# the different documents in the repository. Check generate script for
# details. Edit this file and run the script again to update the
# workflows.
######################################################################

name: Auto publish {{shortname}}

on:
# Worflow runs on pull requests where it makes sure that the spec can still be
# generated, that markup is valid and that there are no broken links, as
# well as on pushes to the default branch where it also deploys the generated
# spec to the gh-pages branch and publishes the result to /TR.
# The "workflow_dispatch" hook allows admins to also trigger the workflow
# manually from GitHub's UI.
pull_request:
paths:
- '{{source}}'{{additionalPaths}}
push:
branches: [main]
paths:
- '{{source}}'{{additionalPaths}}
workflow_dispatch:

jobs:
main:
runs-on: ubuntu-latest
steps:
# See doc at https://github.com/actions/checkout#checkout-v2
- name: Checkout repository
uses: actions/checkout@v4

# See doc at https://w3c.github.io/spec-prod/
# The action only deploys the generated spec to the gh-pages branch when
# the workflow was triggered by a push to the default branch.
- name: Build and validate spec, push to gh-pages branch and deploy to /TR if needed
uses: w3c/spec-prod@v2
with:
TOOLCHAIN: bikeshed
BUILD_FAIL_ON: warning
SOURCE: {{source}}
DESTINATION: {{destination}}
GH_PAGES_BRANCH: gh-pages
W3C_ECHIDNA_TOKEN: ${{ secrets.{{tokenName}} }}
W3C_WG_DECISION_URL: https://github.com/w3c/media-wg/issues/27
W3C_BUILD_OVERRIDE: |
status: {{publicationStatus}}
158 changes: 158 additions & 0 deletions .github/generate-auto-publish-workflows.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
/**********************************************************************
* Companion script to create individual auto publication workflows for
* specifications contained in the repository. Run the script any time
* the auto-publish-template.yml is updated or when the list of specs
* changes below.
**********************************************************************/

/**
* List of properties that can appear to describe a spec.
*/
const properties = [
// Spec shortname (without level), e.g., 'webcodecs'
// (Shortname does not *have* to be the actual published shortname, just
// an identifier used to tell specs apart internally)
// The shortname is derived from the source file name if not provided,
// replacing "_" with "-"
'shortname',

// Spec status on /TR, e.g., 'WD'
'publicationStatus',

// Relative path to source file
'source',

// Relative path to destination file in gh-pages branch (Optional)
// If not provided, the destination file is computed from the source by
// removing `.src`.
'destination',

// Name of the repository secret that contains the publication token for
// Echidna (Optional).
// If not provided, the name is computed from the shortname, e.g.,
// `ECHIDNA_TOKEN_WEBCODECS` for `webcodecs`
'tokenName',

// Additional paths that should trigger the auto-publish script if changed
// on top of the actual source (Optional). Glob patterns may be used.
'additionalPaths'
];


/**
* List of specs for which an auto-publish script needs to be created.
*/
const specs = [
{
shortname: 'webcodecs',
source: 'index.src.html',
publicationStatus: 'WD'
},
{
source: 'codec_registry.src.html',
publicationStatus: 'DRY'
},
{
source: 'avc_codec_registration.src.html',
publicationStatus: 'NOTE-WD'
},
{
source: 'vorbis_codec_registration.src.html',
publicationStatus: 'NOTE-WD'
},
{
source: 'mp3_codec_registration.src.html',
publicationStatus: 'NOTE-WD'
},
{
source: 'aac_codec_registration.src.html',
publicationStatus: 'NOTE-WD'
},
{
source: 'flac_codec_registration.src.html',
publicationStatus: 'NOTE-WD'
},
{
source: 'opus_codec_registration.src.html',
publicationStatus: 'NOTE-WD'
},
{
source: 'av1_codec_registration.src.html',
publicationStatus: 'NOTE-WD'
},
{
source: 'vp9_codec_registration.src.html',
publicationStatus: 'NOTE-WD'
},
{
source: 'vp8_codec_registration.src.html',
publicationStatus: 'NOTE-WD'
},
{
source: 'pcm_codec_registration.src.html',
publicationStatus: 'NOTE-WD'
},
{
source: 'alaw_codec_registration.src.html',
publicationStatus: 'NOTE-WD'
},
{
source: 'ulaw_codec_registration.src.html',
publicationStatus: 'NOTE-WD'
},
{
source: 'hevc_codec_registration.src.html',
publicationStatus: 'NOTE-WD'
},
{
source: 'video_frame_metadata_registry.src.html',
publicationStatus: 'DRY',
tokenName: 'ECHIDNA_TOKEN_VIDEOFRAMEMETADATA_REGISTRY'
}
];


/**
* Main loop, create a workflow per spec
*/
import assert from 'node:assert';
import { readFile, writeFile } from 'node:fs/promises';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';

const scriptPath = dirname(fileURLToPath(import.meta.url));
let template = await readFile(join(scriptPath, 'auto-publish-template.yml'), 'utf8');
template = template.replace(/#{5,}.*#{5,}/s,
`######################################################################
# IMPORTANT: Do not edit this file directly!
#
# This workflow was automatically generated through the
# generate-auto-publish-workflows.mjs script. To update the workflow,
# make changes to the template file and run the script again.
######################################################################`);

for (const spec of specs) {
if (!spec.shortname) {
spec.shortname = spec.source.split('.')[0].replace(/_/g, '-');
}
if (!spec.destination) {
spec.destination = spec.source.replace(/\.src/, '');
}
if (!spec.tokenName) {
spec.tokenName = 'ECHIDNA_TOKEN_' +
spec.shortname.toUpperCase()
.replace(/-/g, '_')
.replace(/_CODEC_/, '_'); // Tokens don't have "_CODEC_" in their name
}
if (spec.additionalPaths) {
spec.additionalPaths = spec.additionalPaths.map(path => `\n - '${path}'`).join('');
}

let content = template;
for (const prop of properties) {
content = content.replace(new RegExp('{{' + prop + '}}', 'g'), spec[prop] ?? '');
}

const filename = join(scriptPath, 'workflows', `auto-publish-${spec.shortname}.yml`);
await writeFile(filename, content, 'utf8');
}
49 changes: 49 additions & 0 deletions .github/workflows/auto-publish-aac-codec-registration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
######################################################################
# IMPORTANT: Do not edit this file directly!
#
# This workflow was automatically generated through the
# generate-auto-publish-workflows.mjs script. To update the workflow,
# make changes to the template file and run the script again.
######################################################################

name: Auto publish aac-codec-registration

on:
# Worflow runs on pull requests where it makes sure that the spec can still be
# generated, that markup is valid and that there are no broken links, as
# well as on pushes to the default branch where it also deploys the generated
# spec to the gh-pages branch and publishes the result to /TR.
# The "workflow_dispatch" hook allows admins to also trigger the workflow
# manually from GitHub's UI.
pull_request:
paths:
- 'aac_codec_registration.src.html'
push:
branches: [main]
paths:
- 'aac_codec_registration.src.html'
workflow_dispatch:

jobs:
main:
runs-on: ubuntu-latest
steps:
# See doc at https://github.com/actions/checkout#checkout-v2
- name: Checkout repository
uses: actions/checkout@v4

# See doc at https://w3c.github.io/spec-prod/
# The action only deploys the generated spec to the gh-pages branch when
# the workflow was triggered by a push to the default branch.
- name: Build and validate spec, push to gh-pages branch and deploy to /TR if needed
uses: w3c/spec-prod@v2
with:
TOOLCHAIN: bikeshed
BUILD_FAIL_ON: warning
SOURCE: aac_codec_registration.src.html
DESTINATION: aac_codec_registration.html
GH_PAGES_BRANCH: gh-pages
W3C_ECHIDNA_TOKEN: ${{ secrets.ECHIDNA_TOKEN_AAC_REGISTRATION }}
W3C_WG_DECISION_URL: https://github.com/w3c/media-wg/issues/27
W3C_BUILD_OVERRIDE: |
status: NOTE-WD
49 changes: 49 additions & 0 deletions .github/workflows/auto-publish-alaw-codec-registration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
######################################################################
# IMPORTANT: Do not edit this file directly!
#
# This workflow was automatically generated through the
# generate-auto-publish-workflows.mjs script. To update the workflow,
# make changes to the template file and run the script again.
######################################################################

name: Auto publish alaw-codec-registration

on:
# Worflow runs on pull requests where it makes sure that the spec can still be
# generated, that markup is valid and that there are no broken links, as
# well as on pushes to the default branch where it also deploys the generated
# spec to the gh-pages branch and publishes the result to /TR.
# The "workflow_dispatch" hook allows admins to also trigger the workflow
# manually from GitHub's UI.
pull_request:
paths:
- 'alaw_codec_registration.src.html'
push:
branches: [main]
paths:
- 'alaw_codec_registration.src.html'
workflow_dispatch:

jobs:
main:
runs-on: ubuntu-latest
steps:
# See doc at https://github.com/actions/checkout#checkout-v2
- name: Checkout repository
uses: actions/checkout@v4

# See doc at https://w3c.github.io/spec-prod/
# The action only deploys the generated spec to the gh-pages branch when
# the workflow was triggered by a push to the default branch.
- name: Build and validate spec, push to gh-pages branch and deploy to /TR if needed
uses: w3c/spec-prod@v2
with:
TOOLCHAIN: bikeshed
BUILD_FAIL_ON: warning
SOURCE: alaw_codec_registration.src.html
DESTINATION: alaw_codec_registration.html
GH_PAGES_BRANCH: gh-pages
W3C_ECHIDNA_TOKEN: ${{ secrets.ECHIDNA_TOKEN_ALAW_REGISTRATION }}
W3C_WG_DECISION_URL: https://github.com/w3c/media-wg/issues/27
W3C_BUILD_OVERRIDE: |
status: NOTE-WD
49 changes: 49 additions & 0 deletions .github/workflows/auto-publish-av1-codec-registration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
######################################################################
# IMPORTANT: Do not edit this file directly!
#
# This workflow was automatically generated through the
# generate-auto-publish-workflows.mjs script. To update the workflow,
# make changes to the template file and run the script again.
######################################################################

name: Auto publish av1-codec-registration

on:
# Worflow runs on pull requests where it makes sure that the spec can still be
# generated, that markup is valid and that there are no broken links, as
# well as on pushes to the default branch where it also deploys the generated
# spec to the gh-pages branch and publishes the result to /TR.
# The "workflow_dispatch" hook allows admins to also trigger the workflow
# manually from GitHub's UI.
pull_request:
paths:
- 'av1_codec_registration.src.html'
push:
branches: [main]
paths:
- 'av1_codec_registration.src.html'
workflow_dispatch:

jobs:
main:
runs-on: ubuntu-latest
steps:
# See doc at https://github.com/actions/checkout#checkout-v2
- name: Checkout repository
uses: actions/checkout@v4

# See doc at https://w3c.github.io/spec-prod/
# The action only deploys the generated spec to the gh-pages branch when
# the workflow was triggered by a push to the default branch.
- name: Build and validate spec, push to gh-pages branch and deploy to /TR if needed
uses: w3c/spec-prod@v2
with:
TOOLCHAIN: bikeshed
BUILD_FAIL_ON: warning
SOURCE: av1_codec_registration.src.html
DESTINATION: av1_codec_registration.html
GH_PAGES_BRANCH: gh-pages
W3C_ECHIDNA_TOKEN: ${{ secrets.ECHIDNA_TOKEN_AV1_REGISTRATION }}
W3C_WG_DECISION_URL: https://github.com/w3c/media-wg/issues/27
W3C_BUILD_OVERRIDE: |
status: NOTE-WD
Loading

0 comments on commit 6fd01eb

Please sign in to comment.