Skip to content
85 changes: 73 additions & 12 deletions .github/workflows/identify-web-features.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,86 @@
# This GitHub Actions workflow identifies web features in new and edited issues.
# Identified features are posted as a comment on the issue.
name: Identify Web Features in Issues
# This GitHub Actions workflow identifies web-features in new and edited focus-area-proposal issues.
# Identified web-features are listed as a comment on the issue.
name: Identify web-features in focus area proposals

on:
# Trigger the workflow either when a single issue is opened, edited, reopened, or labeled.
# The labeled trigger only applies when the label is 'focus-area-proposal'.
issues:
types: [opened, edited]
types: [opened, edited, labeled, reopened]
Comment thread
captainbrosset marked this conversation as resolved.
# Trigger the workflow when we update the package.json file (web-features dependency).
push:
branches: [main]
paths:
- scripts/package.json
- scripts/package-lock.json
# Lets us trigger the job manually.
workflow_dispatch:

permissions:
contents: read
issues: write

jobs:
run-script:

# The process-issue job runs when a single issue is opened, edited, reopened or labeled.
process-issue:
if: >-
github.event_name == 'issues' &&

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, but one could also use a condition like contains(github.event.issue.labels.*.name, 'focus-area-proposal') to only select focus area proposal issues irrespective of the trigger.

(
github.event.action == 'opened' ||
github.event.action == 'edited' ||
github.event.action == 'reopened' ||
(github.event.action == 'labeled' && github.event.label.name == 'focus-area-proposal')
)
runs-on: ubuntu-latest
# Concurrency is used to ensure that only one job per issue runs at a time, with newer
# jobs canceling older ones.
concurrency:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How many jobs might this trigger if we close issues en masse or add a lot of labels? GitHub Actions should just queue everything to eventually run, but if we know it'll be hundreds of jobs at the same time, that seems like it might break?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really here to avoid the case where the same issue is updated multiple times while a job for that issue is already running. With this concurrency block, the next jobs will be queued instead of running in parallel.

If I'm editing the opening comment of an issue twice in less time than it takes the job to run, then I don't run the 2 jobs at the same time, potentially ending up with the wrong content if the second ran faster than the first.

That said, I'm realizing that cancel-in-progress:true would make more sense. We only care about the final state of the issue, not the in-between edits. So a later job on an issue should be allowed to cancel an earlier job. I'll change this.

As for a batch editing of hundreds of issues, I'm not seeing an issue here. We'll let GitHub queue up all the jobs.

group: identify-web-features-issue-${{ github.event.issue.number }}
cancel-in-progress: true
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
cache: npm
cache-dependency-path: scripts/package-lock.json
- name: Install dependencies
run: npm ci
working-directory: scripts
- name: Refresh issue
run: node identify-web-features.js --number ${{ github.event.issue.number }} --repo ${{ github.repository }}
working-directory: scripts
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# The process-all-open-proposals job runs when the package.json file is changed, and updates all issues.
# This is used to refresh all open proposals when the web-features dependency is updated.
# The job can also be triggered manually.
process-all-open-proposals:
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
# Concurrency is used to ensure that only one job per repository runs at a time, with newer
# jobs canceling older ones.
concurrency:
group: identify-web-features-all-open-proposals
cancel-in-progress: true
steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: '22'
- name: Run identification script
run: |
cd scripts
npm install
node identify-web-features.js -n ${{ github.event.issue.number }} -r ${{ github.repository }}
cache: npm
cache-dependency-path: scripts/package-lock.json
- name: Install dependencies
run: npm ci
working-directory: scripts
- name: Refresh all open proposals
run: node identify-web-features.js --all-open-proposals --repo ${{ github.repository }}
working-directory: scripts
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Loading