Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workflow to check we have a paper trail on répertoire changes #629

Merged
merged 29 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Pipeline


on:
pull_request:
branches: ['*']
types: [opened, synchronize, reopened, labeled, unlabeled, ready_for_review, converted_to_draft, edited]

jobs:
labels-for-repertoire-changes:
name: Labels for repertoire changes
outputs:
repertoire-changed: ${{ steps.compare-repertoire.outputs.repertoire-changed }}
pipeline-label: ${{ steps.check-labels.outputs.pipeline-label }}
runs-on: ubuntu-latest
steps:
- name: Checkout merged UnicodeData.txt
uses: actions/checkout@v3
with:
path: merged
sparse-checkout: unicodetools/data/ucd/dev/UnicodeData.txt
- name: Checkout base UnicodeData.txt
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.base.sha }}
path: base
sparse-checkout: unicodetools/data/ucd/dev/UnicodeData.txt
- name: Compare repertoire
id: compare-repertoire
run: |
# Look for changes affecting the first two fields of UnicodeData.txt (code point and name).
sed 's/^\([^;]*;[^;]*\);.*$/\1/' merged/unicodetools/data/ucd/dev/UnicodeData.txt > merged-repertoire.txt
sed 's/^\([^;]*;[^;]*\);.*$/\1/' base/unicodetools/data/ucd/dev/UnicodeData.txt > base-repertoire.txt
if diff base-repertoire.txt merged-repertoire.txt
then echo "repertoire-changed=false" >> "$GITHUB_OUTPUT"
else echo "repertoire-changed=true" >> "$GITHUB_OUTPUT"
fi
Comment on lines +32 to +37
Copy link
Member

Choose a reason for hiding this comment

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

the 'sed' filter might be best in a local file for testing.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a comment, but I don’t think there is much to gain from splitting that regex into its own file.

Copy link
Member

Choose a reason for hiding this comment

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

could be useful on its own… not a high prio

- name: Checkout Python scripts
uses: actions/checkout@v3
with:
sparse-checkout: py/pipeline-workflow
- name: Check pipeline labels
id: check-labels
if: steps.compare-repertoire.outputs.repertoire-changed == 'true'
run: python3 py/pipeline-workflow/compare-repertoire.py
l2-document:
needs: labels-for-repertoire-changes
if: ${{ always() && needs.labels-for-repertoire-changes.outputs.repertoire-changed == 'true' }}
name: Proposal document
runs-on: ubuntu-latest
steps:
- name: Checkout Python scripts
uses: actions/checkout@v3
with:
sparse-checkout: py/pipeline-workflow
- name: Check L2 document
run: |
python3 py/pipeline-workflow/check-l2-document.py
utc-decision:
needs: labels-for-repertoire-changes
if: needs.labels-for-repertoire-changes.outputs.repertoire-changed == 'true' && needs.labels-for-repertoire-changes.outputs.pipeline-label != 'pipeline-recommended-to-UTC'
name: UTC decision
runs-on: ubuntu-latest
steps:
- name: Checkout Python scripts
uses: actions/checkout@v3
with:
sparse-checkout: py/pipeline-workflow
- name: Check UTC decision
run: python3 py/pipeline-workflow/check-utc-decision.py
draft-unless-approved:
needs: labels-for-repertoire-changes
if: needs.labels-for-repertoire-changes.outputs.repertoire-changed == 'true'
name: Draft unless approved
runs-on: ubuntu-latest
steps:
- name: Checkout Python scripts and DerivedAge.txt
uses: actions/checkout@v3
with:
sparse-checkout: |
py/pipeline-workflow
unicodetools/data/ucd/dev/DerivedAge.txt
- name: Check draft status
env:
PIPELINE_LABEL: ${{ needs.labels-for-repertoire-changes.outputs.pipeline-label }}
run: python3 py/pipeline-workflow/check-draft-status.py

3 changes: 3 additions & 0 deletions docs/pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ PR preparation:
- [ ] UTC decisions — Cite _in extenso_
- [ ] data-for-new — Set label
- [ ] pipeline-* — Set label
- [ ] PR button — Set to DRAFT pull request
- unless approved for the upcoming version
- [ ] PR button — Press

## Scripts

Expand Down
19 changes: 19 additions & 0 deletions py/pipeline-workflow/check-draft-status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

import os
import json

pipeline_label = os.environ['PIPELINE_LABEL']

with open("unicodetools/data/ucd/dev/DerivedAge.txt", 'r') as f:
version = f.readline().strip().replace("# DerivedAge-", "").replace(".0.txt", "")

if pipeline_label != "pipeline-" + version:
with open(os.environ['GITHUB_EVENT_PATH'], 'r') as f:
event = json.load(f)
print(event)
draft = event['pull_request']['draft']
if not draft:
print("::error title=PR must be draft::"
"PRs for character additions must be draft unless approved for "
"the upcoming version of Unicode.")
exit(1)
14 changes: 14 additions & 0 deletions py/pipeline-workflow/check-l2-document.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

import os
import json
import re

with open(os.environ['GITHUB_EVENT_PATH'], 'r') as f:
event = json.load(f)
print(event)
pr_body = event['pull_request']['body']
if not re.search(r"L2/\d\d-\d\d\d", pr_body):
print("::error title=Need proposal document::"
"PRs for character additions must include a link to an L2 document in"
" the PR description.")
exit(1)
14 changes: 14 additions & 0 deletions py/pipeline-workflow/check-utc-decision.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

import os
import json
import re

with open(os.environ['GITHUB_EVENT_PATH'], 'r') as f:
event = json.load(f)
print(event)
pr_body = event['pull_request']['body']
if not re.search(r"UTC-\d\d\d-[MC]\d", pr_body):
print("::error title=Need UTC decision::"
"PRs for approved or provisionally assigned must include a link to a "
"UTC decision.")
exit(1)
21 changes: 21 additions & 0 deletions py/pipeline-workflow/compare-repertoire.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

import os
import json

with open(os.environ['GITHUB_EVENT_PATH'], 'r') as f:
event = json.load(f)
print(event)
labels = event['pull_request']['labels']
pipeline_labels = [label for label in labels if label['name'].startswith('pipeline-')]
if not pipeline_labels:
print("::error title=Missing pipeline label::"
"PRs for character additions must have a pipeline label.")
exit(1)
if len(pipeline_labels) > 1:
print("::error title=Multiple pipeline labels::"
"Only one pipeline-* label must be applied.")
exit(1)
label = pipeline_labels[0]
print("Labeled", label)
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
print("pipeline-label=" + label['name'], file=f)
Loading