-
Notifications
You must be signed in to change notification settings - Fork 1
101 lines (89 loc) · 3.54 KB
/
create-pr-if-outdated.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
name: create-pr-if-outdated
on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
env:
BRANCH_NAME: update-date-in-readme
BASE_BRANCH_NAME: main
jobs:
create-pr-if-outdated:
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ env.BASE_BRANCH_NAME }}
- name: update readme
run: |
git_last_updated_date=$(git log -1 --format="%at" -- . ":(exclude)README.md" | xargs -I{} date -d @{} +%Y-%m-%d)
python_version=$(cat .python-version)
echo "git_last_updated_date: $git_last_updated_date"
sed -i "s/.*Last Updated: \(.*\)/- Last Updated: $git_last_updated_date/" README.md
sed -i "s/.*Python Version: \(.*\)/- Python Version: $python_version/" README.md
- name: check if need to commit
id: need_commit
run: |
if [[ -n "$(git status --porcelain)" ]]; then
echo "need_commit=true" >> "$GITHUB_OUTPUT"
else
echo "need_commit=false" >> "$GITHUB_OUTPUT"
fi
# GitHub Actions are NOT triggered in this PR
- name: create-pull-request
if: steps.need_commit.outputs.need_commit == 'true'
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: 'chore: update readme (github token)'
branch: update-readme
title: 'chore: update readme (github token)'
body: 'Update readme automatically (github token)'
base: main
delete-branch: true
create-pr-with-github-app:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ env.BASE_BRANCH_NAME }}
- name: update readme
run: |
git_last_updated_date=$(git log -1 --format="%at" -- . ":(exclude)README.md" | xargs -I{} date -d @{} +%Y-%m-%d)
python_version=$(cat .python-version)
echo "git_last_updated_date: $git_last_updated_date"
sed -i "s/.*Last Updated: \(.*\)/- Last Updated: $git_last_updated_date/" README.md
sed -i "s/.*Python Version: \(.*\)/- Python Version: $python_version/" README.md
- name: check if need to commit
id: need_commit
run: |
if [[ -n "$(git status --porcelain)" ]]; then
echo "need_commit=true" >> "$GITHUB_OUTPUT"
else
echo "need_commit=false" >> "$GITHUB_OUTPUT"
fi
- name: create-github-app-token
if: steps.need_commit.outputs.need_commit == 'true'
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.GH_TEST_APP_ID }}
private-key: ${{ secrets.GH_TEST_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
# GitHub Actions are triggered in this PR
- name: create-pull-request
id: create-pull-request
if: steps.need_commit.outputs.need_commit == 'true'
uses: peter-evans/create-pull-request@v7
with:
token: ${{ steps.app-token.outputs.token }}
commit-message: 'chore: update readme (github app)'
branch: update-readme-github-app
title: 'chore: update readme (github app)'
body: 'Update readme automatically (github app)'
base: main
delete-branch: true
- name: enable pr auto merge
run: gh pr merge --squash --auto ${{ steps.create-pull-request.outputs.pull-request-number }}
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}