-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #192 from swryan/3048_poem_integrated
Added a workflow to update a POEM's status to 'Integrated'
- Loading branch information
Showing
5 changed files
with
137 additions
and
4 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/usr/bin/env python | ||
|
||
import sys | ||
import update_readme | ||
|
||
|
||
PASS = 0 | ||
FAIL = 1 | ||
|
||
|
||
def update_integrated(poem_id): | ||
""" | ||
Modify a POEM markdown file to indicate that it's status is 'Integrated'. | ||
Parameters | ||
---------- | ||
poem_id : int | ||
The id of a POEM markdown file in the root of the repo. | ||
Returns | ||
------- | ||
status : int | ||
0 if the operation is successful otherwise 1 | ||
""" | ||
filename = f'POEM_{poem_id:0>3}.md' | ||
|
||
print(f'updating {filename}') | ||
|
||
try: | ||
with open(filename, 'r') as poem_md: | ||
lines = poem_md.readlines() | ||
except IOError: | ||
return FAIL | ||
|
||
in_status = False | ||
success = False | ||
|
||
try: | ||
with open(filename, 'w') as poem_md: | ||
for line in lines: | ||
lu = line.upper().strip() | ||
if lu.startswith('STATUS:'): | ||
in_status = True | ||
print(line, file=poem_md, end='') | ||
elif in_status and '[' in line: | ||
left = line[:line.find('[')] | ||
right = line[line.find(']'):] | ||
if left and right: | ||
if lu.endswith('INTEGRATED'): | ||
print(f'{left}[x{right}', file=poem_md, end='') | ||
in_status = False | ||
success = True | ||
else: | ||
print(f'{left}[ {right}', file=poem_md, end='') | ||
else: | ||
print(line, file=poem_md, end='') | ||
else: | ||
print(line, file=poem_md, end='') | ||
except IOError: | ||
return FAIL | ||
|
||
if success: | ||
print(f"Updated status in '{poem_md}' to Integrated") | ||
return update_readme.update_readme() | ||
else: | ||
return FAIL | ||
|
||
|
||
if __name__ == '__main__': | ||
exit(update_integrated(sys.argv[1])) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# This workflow updates the status of a POEM to 'Integrated' | ||
|
||
name: Update POEM status to Integrated | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
poem_integrated: | ||
description: 'ID of POEM to be marked as Integrated' | ||
required: true | ||
default: 0 | ||
|
||
jobs: | ||
integrate_poem: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: 3.11 | ||
|
||
- name: Run script | ||
env: | ||
POEM_ID: ${{ github.event.inputs.poem_integrated }} | ||
run: python ./.github/scripts/update_integrated.py $POEM_ID | ||
|
||
- name: Commit and push if changed | ||
env: | ||
POEM_ID: ${{ github.event.inputs.poem_integrated }} | ||
run: | | ||
git add . | ||
git diff | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "GitHub Action" | ||
POEM_NO="$(echo $POEM_ID | sed 's/^0*//')" | ||
POEM_ID="$(printf '%03d' $POEM_NO)" | ||
git commit -m "Mark POEM_$POEM_ID as Integrated" -a || echo "No changes to commit" | ||
git push | ||
- name: Notify slack | ||
uses: act10ns/[email protected] | ||
with: | ||
webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }} | ||
status: ${{ job.status }} | ||
message: | | ||
Status of POEM_${{ github.event.inputs.poem_integrated }} was transitioned to `Integrated`. | ||
${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | ||
if: success() | ||
|
||
- name: Notify slack | ||
uses: act10ns/[email protected] | ||
with: | ||
webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }} | ||
status: ${{ job.status }} | ||
message: | | ||
Status of POEM_${{ github.event.inputs.poem_integrated }} WAS NOT transitioned to `Integrated`. | ||
${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | ||
if: failure() |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.pyc | ||
*~ |