-
-
Notifications
You must be signed in to change notification settings - Fork 17
113 lines (96 loc) · 3.56 KB
/
check-for-updates.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
name: Check for tzdata updates
on:
pull_request:
schedule:
- cron: '0 9 * * *' # Runs daily at 9AM UTC
workflow_dispatch:
jobs:
check-pr-exists:
runs-on: ubuntu-latest
outputs:
pr_exists: ${{ steps.check_pr_exists.outputs.pr_exists }}
steps:
- name: Check if PR already exists
id: check_pr_exists
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_EXISTS=$(gh pr --repo $GITHUB_REPOSITORY \
list --search "Update tzdata to version" \
--json number --jq '.[] | .number')
if [ -n "$PR_EXISTS" ]; then
echo "A PR updating the tzdata version already exists: https://github.com/python/tzdata/pulls/${PR_EXISTS}"
echo "::set-output name=pr_exists::true"
exit 0
else
echo "::set-output name=pr_exists::false"
fi
check-for-updates:
runs-on: ubuntu-latest
needs: check-pr-exists
permissions:
pull-requests: write
if: needs.check-pr-exists.outputs.pr_exists == 'false' # Run only if no PR exists
outputs:
changes_detected: ${{ steps.check_changes.outputs.changes_detected }}
steps:
- name: Check out repository (shallow)
uses: actions/checkout@v3
with:
fetch-depth: 1 # Shallow clone to save time
- name: Set up Python 3.12
uses: actions/setup-python@v4
with:
python-version: '3.12'
- name: Install dependencies
run: |
python -m pip install tox
sudo apt-get install gh
- name: Run tox update
run: tox -e update -- --no-skip-existing
- name: Check for repository changes and commit
id: check_changes
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Action"
# Check for changes
if git diff --quiet; then
echo "No changes detected."
echo "::set-output name=changes_detected::false"
exit 0
fi
echo "Test" > news.d/2024c.md
# Check for changes in the news.d directory
git add -A
news_files=$(git diff --cached --name-only --diff-filter=A | grep '^news.d/.*\.md' || true)
if [ -z "$news_files" ]; then
echo "No new file in news.d, failing the job."
exit 1
fi
if [ $(echo "$news_files" | wc -l) -ne 1 ]; then
echo "More than one new file added in news.d, failing the job."
exit 1
fi
echo "::set-output name=changes_detected::true"
# Extract TZDATA_VERSION from filename
TZDATA_VERSION=$(basename "$news_files" .md)
# Extract TZDATA_NEWS from file content
TZDATA_NEWS=$(cat "$news_files")
echo "TZDATA_VERSION=$TZDATA_VERSION" >> $GITHUB_ENV
echo "TZDATA_NEWS=$TZDATA_NEWS" >> $GITHUB_ENV
- name: Create PR
id: commit_changes
if: steps.check_changes.outputs.changes_detected == 'true'
run: |
git commit -m "Update tzdata to version $TZDATA_VERSION" \
-m "$TZDATA_NEWS"
- name: Create pull request
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: steps.check_changes.outputs.changes_detected == 'true'
run: |
gh pr create --title "Update tzdata to version $TZDATA_VERSION" \
--body "$TZDATA_NEWS" \
--base main \
--head $(git rev-parse --abbrev-ref HEAD) \
--label "automatic-updates"