diff --git a/.github/scripts/update_integrated.py b/.github/scripts/update_integrated.py new file mode 100644 index 00000000..7bceede9 --- /dev/null +++ b/.github/scripts/update_integrated.py @@ -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])) diff --git a/.github/workflows/poem_linter.yml b/.github/workflows/poem_linter.yml index 2b21ae3d..81410f5c 100644 --- a/.github/workflows/poem_linter.yml +++ b/.github/workflows/poem_linter.yml @@ -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 diff --git a/.github/workflows/update_integrated.yml b/.github/workflows/update_integrated.yml new file mode 100644 index 00000000..7040c9fb --- /dev/null +++ b/.github/workflows/update_integrated.yml @@ -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 "github-action@github.com" + 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/slack@v2.0.0 + 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/slack@v2.0.0 + 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() diff --git a/.github/workflows/update_readme.yml b/.github/workflows/update_readme.yml index 63ee28c6..f6059fea 100644 --- a/.github/workflows/update_readme.yml +++ b/.github/workflows/update_readme.yml @@ -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 diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..f3d74a9a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.pyc +*~