-
Notifications
You must be signed in to change notification settings - Fork 26
82 lines (69 loc) · 3.03 KB
/
generate.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
# regenerates CHANGELOG.md and dist/index.js if necessary
#
# CHANGELOG.md is generated by https://github.com/github-changelog-generator/github-changelog-generator
# This job verifies, that it contains always the current content
# and also pushes the updated changelog to https://github.com/pmd/pmd-github-action/blob/main/CHANGELOG.md
#
# When you reference an action with `uses:` in a workflow,
# `index.js` is the code that will run.
# For our project, we generate this file through a build process from other source files.
# We need to make sure the checked-in `index.js` actually matches what we expect it to be.
# This job verifies, that it contains always the current content
# and also pushes the any necessary updates
name: Regenerate CHANGELOG and dist
on:
push:
branches:
- main
workflow_dispatch:
jobs:
regenerate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
bundler-cache: true
- name: Run github_changelog_generator
shell: bash
run: |
bundle exec github_changelog_generator --token ${{ secrets.GITHUB_TOKEN }}
- name: Compare the expected and actual CHANGELOG.md
run: |
if [ "$(git diff CHANGELOG.md | wc -l)" -gt "0" ]; then
echo "Detected uncommitted changes after build. See status below:"
git diff
echo "changelog=outdated" >> $GITHUB_ENV
else
echo "changelog=current" >> $GITHUB_ENV
fi
- name: Push changes to CHANGELOG.md
if: ${{ github.repository == 'pmd/pmd-github-action' && ( github.event_name == 'push' || github.event_name == 'workflow_dispatch' ) && env.changelog == 'outdated' }}
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Actions (pmd-bot)"
git add CHANGELOG.md && git commit -m 'Updated CHANGELOG.md' && git push origin main
- name: Setup Node.js
uses: actions/[email protected]
with:
node-version: 20
- name: Install dependencies
run: npm ci
- name: Rebuild the dist/ directory
run: npm run package
- name: Compare the expected and actual dist/ directories
run: |
if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then
echo "Detected uncommitted changes after build. See status below:"
git diff
echo "dist=outdated" >> $GITHUB_ENV
else
echo "dist=current" >> $GITHUB_ENV
fi
- name: Push changes to dist/
if: ${{ github.repository == 'pmd/pmd-github-action' && ( github.event_name == 'push' || github.event_name == 'workflow_dispatch' ) && env.dist == 'outdated' }}
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Actions (pmd-bot)"
git add dist && git commit -m 'Updated dist' && git push origin main