-
Notifications
You must be signed in to change notification settings - Fork 5
96 lines (96 loc) · 4.33 KB
/
update_range_message.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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}}