-
Notifications
You must be signed in to change notification settings - Fork 592
121 lines (103 loc) · 3.42 KB
/
Copy pathauto-changelog.yml
File metadata and controls
121 lines (103 loc) · 3.42 KB
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
114
115
116
117
118
119
120
name: Update Changelog
on:
push:
branches:
- Starlight
- starlight-dev
permissions:
contents: write
pull-requests: read
actions: read
env:
BRANCH_NAME: ${{ github.ref_name }}
jobs:
wait-for-que:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.x"
- name: Install Dependencies
run: |
pip install PyGithub
- name: Wait for Que to finish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY: ${{ github.repository }}
WORKFLOW_RUN_NUMBER: ${{ github.run_number }}
WORKFLOW_NAME: ${{ github.workflow }}
run: |
python ./Tools/_Starlight/wait_for_actions.py
echo "Script exited with code $?"
update-changelog:
runs-on: ubuntu-latest
needs: wait-for-que
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Get Pull Request Number via GH
id: get_pr
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const pr = await github.rest.repos.listPullRequestsAssociatedWithCommit({
owner: context.repo.owner,
repo: context.repo.repo,
commit_sha: context.sha
});
if (pr.data.length === 0) {
console.log("No PR found for this branch. Skipping changelog update.");
return "";
}
console.log(`PR Number: ${pr.data[0].number}`);
return pr.data[0].number;
#re checkout
- name: Re-checkout repository
if: steps.get_pr.outputs.result != ''
uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
- name: Set up Python
if: steps.get_pr.outputs.result != ''
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install Dependencies
if: steps.get_pr.outputs.result != ''
run: |
pip install pyyaml PyGithub
- name: Parse PR and Update Changelog
if: steps.get_pr.outputs.result != ''
env:
CHANGELOG_FILE_PATH: 'Resources/Changelog/ChangelogStarlight.yml'
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ steps.get_pr.outputs.result }}
GITHUB_REPOSITORY: ${{ github.repository }}
run: |
python ./Tools/_Starlight/update_changelog.py
echo "Script exited with code $?"
- name: Display changelog after update
if: steps.get_pr.outputs.result != ''
run: |
cat "Resources/Changelog/ChangelogStarlight.yml"
- name: Git status before commit
if: steps.get_pr.outputs.result != ''
run: |
git status
- name: Commit and push changes
if: steps.get_pr.outputs.result != ''
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add "Resources/Changelog/ChangelogStarlight.yml"
if git diff --cached --quiet; then
echo "No changes to commit."
else
git pull
git commit -m "Update changelog for PR #${{ steps.get_pr.outputs.result }} [skip ci]"
git push
fi