-
Notifications
You must be signed in to change notification settings - Fork 2
/
action.yaml
157 lines (139 loc) · 5.48 KB
/
action.yaml
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
152
153
154
155
156
157
name: 'Changie release'
description: 'Create a changie release'
branding:
icon: 'award'
color: 'green'
inputs:
github-token:
description: 'The GitHub token'
required: true
changie-version:
description: 'The version of changie to use'
required: false
default: 'latest'
version-command:
description: 'Command to set the version in the package'
required: false
release-workflow:
description: "Name of the release workflow to trigger"
required: false
pull-request-labels:
description: "Comma separated or newline-separated list of labels to add to the pull request"
required: false
runs:
using: "composite"
steps:
# When changelog is update, notes are added and unreleased drafts are
# deleted we can safely assume that we need to do a release
- uses: dorny/paths-filter@v3
id: changes
with:
filters: |
changelog:
- added|modified: CHANGELOG.md
notes:
- added: .changes/*.md
unreleased:
- deleted: .changes/unreleased/*.yaml
# Define two output variables:
# - create_release: true if there are open changes, false otherwise
# - is_release: true if this push is the result of a release. Combines
# the status of the changelog, notes and unreleased checks for ease
- name: Check for changelog items
id: status
shell: bash
run: |
if find .changes/unreleased/ -name '*.yaml' | grep .; then
echo "create_release=true" >> $GITHUB_OUTPUT
echo "is_release=false" >> $GITHUB_OUTPUT
else
echo "create_release=false" >> $GITHUB_OUTPUT
echo "is_release=${IS_RELEASE}" >> $GITHUB_OUTPUT
fi
env:
IS_RELEASE: ${{ steps.changes.outputs.changelog == 'true' && steps.changes.outputs.notes == 'true' && steps.changes.outputs.unreleased == 'true' }}
- name: Output changes
if: steps.status.outputs.create_release == 'true'
uses: miniscruff/changie-action@v2
id: changelog
with:
version: ${{ inputs.changie-version }}
args: batch --dry-run auto
- name: Batch changes
if: steps.status.outputs.create_release == 'true'
uses: miniscruff/changie-action@v2
with:
version: ${{ inputs.changie-version }}
args: batch auto
- name: Merge changes
if: steps.status.outputs.create_release == 'true'
uses: miniscruff/changie-action@v2
with:
version: ${{ inputs.changie-version }}
args: merge
- name: Get the latest version
id: latest
if: steps.status.outputs.create_release == 'true' || steps.status.outputs.is_release == 'true'
uses: miniscruff/changie-action@v2
with:
version: ${{ inputs.changie-version }}
args: latest
- name: Set the version in the package
if: inputs.version-command && steps.status.outputs.create_release == 'true'
run: ${{ inputs.version-command }}
shell: bash
env:
PACKAGE_VERSION: ${{ steps.latest.outputs.output }}
- name: Create Pull Request
uses: peter-evans/create-pull-request@v7
if: steps.status.outputs.create_release == 'true'
with:
title: Release ${{ steps.latest.outputs.output }}
branch: release/${{ steps.latest.outputs.output }}
commit-message: Release ${{ steps.latest.outputs.output }}
token: ${{ inputs.github-token }}
labels: ${{ inputs.pull-request-labels }}
body: |
This PR was created by the [Changie release GitHub action](https://github.com/labd/changie-release-action). When you're ready to do a release, you can merge this and the tag ${{ steps.latest.outputs.output }} will be created${{ inputs.release-workflow != '' && format(' and the {0} workflow will be started', inputs.release-workflow) || '' }}. If you're not ready to do a release yet, that's fine, whenever you add more changes to main, this PR will be updated.
# Releases
${{ steps.changelog.outputs.output }}
- name: Create tag
if: steps.status.outputs.is_release == 'true'
uses: actions/github-script@v7
env:
VERSION: ${{ steps.latest.outputs.output }}
with:
github-token: ${{ inputs.github-token }}
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/tags/${process.env.VERSION}`,
sha: context.sha
})
- name: Create GitHub release
if: steps.status.outputs.is_release == 'true'
uses: actions/github-script@v7
env:
VERSION: ${{ steps.latest.outputs.output }}
GITHUB_RELEASE_BODY: ${{ steps.changelog.outputs.output }}
with:
github-token: ${{ inputs.github-token }}
retries: 3
script: |
github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
name: process.env.VERSION,
body: process.env.GITHUB_RELEASE_BODY,
tag_name: process.env.VERSION,
draft: false,
})
# We need to manually trigger a release workflow since GitHub actions cannot
# automatically trigger other GitHub actions.
- name: Trigger release
if: steps.status.outputs.is_release == 'true' && inputs.release-workflow != ''
shell: bash
run: gh workflow run ${{ inputs.release-workflow }} --ref ${{ steps.latest.outputs.output }}
env:
GH_TOKEN: ${{ inputs.github-token }}