Skip to content

Integrate nohttp

Integrate nohttp #115

name: Update an issues state in a mapping
on:
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#onevent_nametypes
issues:
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#issues
types:
- reopened
- closed
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions
permissions:
contents: write # for "git push"
defaults:
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#defaultsrun
run:
# Enable fail-fast behavior using set -eo pipefail
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#exit-codes-and-error-action-preference
shell: bash
jobs:
update-mapping:
name: Update an issues state
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idruns-on
runs-on: ubuntu-20.04
steps:
- name: Clone source code
uses: actions/checkout@v4.1.6 # https://github.com/actions/checkout
with:
# Whether to configure the token or SSH key with the local git config. Default: true
persist-credentials: true
# https://github.com/actions/checkout#checkout-a-different-branch
ref: generated-todos
#- name: Show a payload
# env:
# GITHUB_CONTEXT: ${{ toJson(github) }}
# run: echo "$GITHUB_CONTEXT"
- name: Update issue state
env:
ISSUE_ID: ${{ github.event.issue.number }}
NEW_STATE: ${{ github.event.action }}
run: >-
awk \
-v issue_id="$ISSUE_ID" \
-v new_state="$NEW_STATE" \
'BEGIN { FS="\t"; OFS="\t" } { if ($2 == issue_id && $3 != new_state) { $3=new_state }; print $0 }' \
todos-on-github.tsv \
> todos-on-github.tsv.new
- name: Check for the changes
run: |
if ! diff --brief todos-on-github.tsv todos-on-github.tsv.new >/dev/null; then
echo 'todos-on-github.tsv has been modified'
mv todos-on-github.tsv.new todos-on-github.tsv
PUZZLES_MAPPING_MODIFIED=yes
else
PUZZLES_MAPPING_MODIFIED=no
fi
# Make variable available for the next steps
echo "PUZZLES_MAPPING_MODIFIED=$PUZZLES_MAPPING_MODIFIED" | tee -a "$GITHUB_ENV"
- name: Commit updated mapping
if: env.PUZZLES_MAPPING_MODIFIED == 'yes'
env:
GIT_AUTHOR_NAME: 'GitHub Action'
GIT_COMMITTER_NAME: 'GitHub Action'
GIT_AUTHOR_EMAIL: 'slava.semushin+ghaction@gmail.com'
GIT_COMMITTER_EMAIL: 'slava.semushin+ghaction@gmail.com'
run: |
git add todos-on-github.tsv
git commit todos-on-github.tsv -m 'chore: update issues state'
git push
- name: Cleanup
if: always()
run: |
[ ! -f todos-on-github.tsv.new ] || rm -fv todos-on-github.tsv.new