-
Notifications
You must be signed in to change notification settings - Fork 0
151 lines (145 loc) · 5.42 KB
/
build_event_prep.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
name: Generate Release Content
on:
pull_request:
branches:
- main
jobs:
label:
runs-on: ubuntu-latest
outputs:
release-type: ${{ steps.parse-labels.outputs.release-type }}
change-type: ${{ steps.parse-labels.outputs.change-type }}
previous-version: ${{ steps.prevtag.outputs.previousversion }}
release-version: ${{ steps.new-version-standard.outputs.new-version }}
changelog-content: ${{ steps.set-changelog.outputs.changelog }}
permissions:
issues: write
pull-requests: write
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
path: src
fetch-depth: 0
- name: Parse and Add Labels
id: parse-labels
uses: actions/github-script@v7
with:
script: |
const script = require('./src/.github/scripts/pr-scripts/parse-add-labels.js')
await script({github, context, core})
- name: Detect previous version number
id: prevtag
working-directory: src
run: |
if previousversion=$(git describe --tags --match="[0-9]*" --abbrev=0 HEAD 2>/dev/null); then
echo "previousversion=$(git describe --tags --match="[0-9]*" --abbrev=0 HEAD)" >> "$GITHUB_OUTPUT"
else
echo "previousversion=0.0.0" >> "$GITHUB_OUTPUT"
fi
- name: Determine new version number (Standard)
uses: actions/github-script@v7
id: new-version-standard
env:
PREV_VERSION: ${{ steps.prevtag.outputs.previousversion }}
RELEASE_TYPE: ${{ steps.parse-labels.outputs.release-type }}
with:
script: |
const script = require('./src/.github/scripts/pr-scripts/plan_new-version.js')
await script({github, context, core})
- name: Extract changelog entry
uses: actions/github-script@v7
id: set-changelog
env:
releaseversion: ${{ steps.new-version-standard.outputs.new-version }}
changetype: ${{ steps.parse-labels.outputs.change-type }}
with:
script: |
const script = require('./src/.github/scripts/pr-scripts/plan_changelog.js')
await script({github, context, core})
comment:
needs: label
if: needs.label.outputs.release-type != 'no-release'
permissions:
issues: write
pull-requests: write
contents: read
runs-on: ubuntu-latest
name: 'Comment on PR'
steps:
- name: Clone Repo to determine previous git tag
uses: actions/checkout@v4
with:
path: src
fetch-depth: 0
- uses: actions/github-script@v7
env:
releaseVersion: '${{ needs.label.outputs.release-version }}'
previousVersion: '${{ needs.label.outputs.previous-version }}'
changelogContent: '${{ needs.label.outputs.changelog-content }}'
with:
script: |
const script = require('./src/.github/scripts/pr-scripts/comment_pr-comment.js')
await script({github, context, core})
update-files:
needs: label
permissions:
issues: write
pull-requests: write
contents: write
runs-on: ubuntu-latest
name: 'Update release files.'
steps:
- name: "Checkout Repository"
uses: actions/checkout@v4
with:
path: src
fetch-depth: 0
ref: 'main'
- name: Fetch Release Notes
id: fetch-release-notes
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const path = require('path');
const readFile = (filePath) => fs.readFileSync(filePath, 'utf-8').trim();
const changelogPath = 'src/CHANGELOG.md';
const changelogContent = readFile(changelogPath);
core.setOutput('existing-changelog', changelogContent);
- name: Prepend New Changelog Content
id: prepend-changelog
run: |
mkdir -p tmp && cd tmp
echo "# Changelog" > updated-changelog.md
echo "" >> updated-changelog.md
printf "${{ needs.label.outputs.changelog-content }}" >> updated-changelog.md
printf "${{ steps.fetch-release-notes.outputs.existing-changelog }}" | sed '1d' >> updated-changelog.md
- name: Generate Readme Content
working-directory: src
run: |
npm install js-yaml --save
node .github/scripts/generate-readme.js
- name: Checkout Pull Request Branch Again
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0
path: src
- name: Update package.json with version
working-directory: src
run: |
sed -i 's/"version": "[^"]*"/"version": "${{ needs.label.outputs.release-version }}"/' package.json
- name: Commit and Push Updates
working-directory: src
run: |
git config user.name "GitHub-Actions[bot]"
git config user.email "GitHub-Actions[bot]@users.noreply.github.com"
cp ${{ github.workspace }}/tmp/updated-changelog.md CHANGELOG.md
cp ${{ github.workspace }}/tmp/new-README.md README.md
git add CHANGELOG.md README.md package.json
if ! git diff-index --quiet HEAD; then
git commit -m "Bot: Updating CHANGELOG, README and package.json for release based on #${{ github.event.pull_request.number }}"
git push origin ${{ github.event.pull_request.head.ref }}
fi