Skip to content

Update RangeMessage.xml #631

Update RangeMessage.xml

Update RangeMessage.xml #631

name: Update RangeMessage.xml
on:
schedule:
- cron: "37 3 * * *"
workflow_dispatch:
permissions:
contents: write
issues: write
pull-requests: write
jobs:
update-ranges:
runs-on: ubuntu-latest
# create a environment named with this key
# Repo > Settings > Environments
# Add a secret named ISSUES_GITHUB_TOKEN
# The secret value is a classic Github token with repo access
# Account > Settings > Developer Settings > Personal Access Tokens > Tokens (classic)
environment: action-pull-request
env:
RANGE_MESSAGES_SAME: 1
CHANGES_PUSHED: 0
steps:
- uses: actions/checkout@v3
- name: old version
run: |
perl -0777 -ne 'm/^our \x24VERSION\s+=\s+\x27(.+?)\x27/m and print qq(OLD_VERSION=$1)' lib/Business/ISBN/Data.pm >> $GITHUB_ENV
- name: setup packages
run: |
sudo apt-get update
sudo apt -y install libxml2-utils
- name: setup git config
run: |
git config --global user.name "GitHub Actions Bot"
git config --global user.email "<>"
- name: Fetch RangeMessage.xml
id: fetch
run: |
curl https://www.isbn-international.org/export_rangemessage.xml > lib/Business/ISBN/RangeMessage.xml.new
ls -l
- name: Check new RangeMessage.xml
id: check
run: |
xmllint lib/Business/ISBN/RangeMessage.xml.new > /dev/null
- name: Check if RangeMessage is updated
id: compare
continue-on-error: true
run: |
perl util/range_messages_differ.pl lib/Business/ISBN/RangeMessage.xml lib/Business/ISBN/RangeMessage.xml.new
echo "RANGE_MESSAGES_SAME=$?" >> $GITHUB_ENV
- name: Update module data
id: update
if: ${{ env.RANGE_MESSAGES_SAME == 0 }}
run: |
mv lib/Business/ISBN/RangeMessage.xml.new lib/Business/ISBN/RangeMessage.xml
perl -Ilib examples/make_default_data.pl
perl -0777 -ne 'm/^our \x24VERSION\s+=\s+\x27(.+?)\x27/m and print qq(NEW_VERSION=$1\n)' lib/Business/ISBN/Data.pm >> $GITHUB_ENV
perl -0777 -ne 'm/^our \x24VERSION\s+=\s+\x27(.+?)\x27/m and print qq(PR_BRANCH_NAME=actions/data-update-$1\n)' lib/Business/ISBN/Data.pm >> $GITHUB_ENV
perl Makefile.PL
make test
- name: Commit RangeMessage.xml
id: commit
if: ${{ env.RANGE_MESSAGES_SAME == 0 }}
continue-on-error: true
run: |
echo
git diff
git add lib/Business/ISBN/RangeMessage.xml lib/Business/ISBN/Data.pm
git commit -m "RangeMessage.xml for ${{ env.NEW_VERSION }}" lib/Business/ISBN/RangeMessage.xml lib/Business/ISBN/Data.pm
echo "CHANGES_PUSHED=1" >> $GITHUB_ENV
- name: Create Pull Request
id: pull-request
if: ${{ env.CHANGES_PUSHED == 1 }}
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.ISSUES_GITHUB_TOKEN }}
assignees: briandfoy
labels: "Type: data update"
title: Data update for ${{env.NEW_VERSION}}
delete-branch: true
branch: ${{env.PR_BRANCH_NAME}}
base: master
- name: Merge the pull request
if: ${{ env.CHANGES_PUSHED == 1 }}
env:
GH_TOKEN: ${{ secrets.ISSUES_GITHUB_TOKEN }}
shell: bash
run: |
echo "Approving pull request <${{ steps.pull-request.outputs.pull-request-number }}>"
gh pr review --approve ${{ steps.pull-request.outputs.pull-request-number }}
echo "Merging pull request <${{ steps.pull-request.outputs.pull-request-number }}>"
gh pr merge ${{ steps.pull-request.outputs.pull-request-number }} --admin --squash
- name: Clean up
continue-on-error: true
if: ${{ env.RANGE_MESSAGES_SAME == 0 }}
run: |
git push origin :${{env.PR_BRANCH_NAME}}