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

Added a workflow to update a POEM's status to 'Integrated' #192

Merged
merged 1 commit into from
Nov 30, 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
70 changes: 70 additions & 0 deletions .github/scripts/update_integrated.py
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]))
4 changes: 2 additions & 2 deletions .github/workflows/poem_linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ jobs:

steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.8
- name: Run script
Expand Down
61 changes: 61 additions & 0 deletions .github/workflows/update_integrated.yml
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()
4 changes: 2 additions & 2 deletions .github/workflows/update_readme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:

steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Set up Python 3.8
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.8

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.pyc
*~