-
Notifications
You must be signed in to change notification settings - Fork 41
141 lines (126 loc) · 5.28 KB
/
process-changelog.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
name: "Release - Changelog"
# This action will run when it is triggered manually
on:
workflow_dispatch:
inputs:
release-version:
description: "The release version for which the action should process the changelog (e.g. 4.5.0) (default: will try to figure it out)"
default: 'figure-it-out'
required: true
type: string
release-date:
description: "The release date in human-readable format (default: 'today')."
required: false
default: "today"
type: string
action-type:
description: "Whether this is to amend or generate the changelog entries (default: 'generate')."
required: true
default: "generate"
type: choice
options:
- amend
- generate
- amend-version
defaults:
run:
shell: bash
jobs:
process-changelog:
name: "Process the changelog"
runs-on: ubuntu-latest
env:
CHANGELOG_ACTION: ${{ inputs.action-type }}
RELEASE_VERSION: ${{ inputs.release-version }}
RELEASE_DATE: ${{ inputs.release-date }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
fetch-depth: 0
- name: Configure PHP environment
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
- name: Set up Composer
run: composer install --no-progress --ignore-platform-reqs
- name: Set Variables
id: vars
run: echo "sha_short=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_OUTPUT
- name: Set up Git configuration
run: |
git config --global user.email "actions@github.com"
git config --global user.name "github-actions"
- name: Check for .puprc file and paths.versions
id: check-puprc
run: |
if [ ! -f ".puprc" ]; then
echo "Error: .puprc file not found" >> $GITHUB_STEP_SUMMARY
exit 1
fi
if ! jq -e '.paths.versions' .puprc > /dev/null; then
echo "Error: paths.versions not found in .puprc" >> $GITHUB_STEP_SUMMARY
exit 1
fi
- name: Figure out Version
id: figure_out_version
run: |
if [ "$RELEASE_VERSION" == "figure-it-out" ]; then
existing_version=""
while read -r version; do
echo "Processing version info: $version"
file=$(echo "$version" | jq -r '.file')
regex=$(echo "$version" | jq -r '.regex')
existing_version=$(grep -Po "$regex" "$file" | grep -Po '(\d+\.\d+\.\d+(\.\d+)?)')
if [ -n "$existing_version" ]; then
echo "Release version: $existing_version"
echo "RELEASE_VERSION=$existing_version" >> $GITHUB_OUTPUT
break
fi
done < <(jq -c '.paths.versions[]' .puprc)
else
echo "Release version: $RELEASE_VERSION"
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_OUTPUT
fi
- name: "Format the release date"
id: format_date
run: |
RELEASE_DATE=$( date "+%Y-%m-%d" -d "$RELEASE_DATE" ) # Release date formatted as YYYY-MM-DD
echo "Release date: $RELEASE_DATE"
echo "RELEASE_DATE=$RELEASE_DATE" >> $GITHUB_OUTPUT
- name: Create new branch
id: versions
run: |
changeBranch="task/process-changelog/${{ steps.format_date.outputs.RELEASE_DATE }}/${{ steps.figure_out_version.outputs.RELEASE_VERSION }}/${{ steps.vars.outputs.sha_short }}"
git checkout -b "$changeBranch"
git push origin "$changeBranch"
- name: "Process changelog"
id: process_changelog
uses: ./.github/actions/process-changelog
with:
release-version: ${{ steps.figure_out_version.outputs.RELEASE_VERSION }}
release-date: ${{ steps.format_date.outputs.RELEASE_DATE }}
action-type: ${{ env.CHANGELOG_ACTION }}
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
id: cpr
with:
token: ${{ secrets.GHA_BOT_TOKEN_MANAGER }}
base: ${{ github.ref }}
branch: "task/process-changelog/${{ steps.format_date.outputs.RELEASE_DATE }}/${{ steps.figure_out_version.outputs.RELEASE_VERSION }}/${{ steps.vars.outputs.sha_short }}"
title: "Process changelog for ${{ github.ref }}"
body: |
This is an automated PR created by ${{ github.actor }}.
It was generated by [this GitHub Action](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}).
labels: "automation"
commit-message: |
Process changelog for ${{ github.ref }}
This is an automated PR created by ${{ github.actor }}.
Generated by: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
- name: Check outputs
if: ${{ steps.cpr.outputs.pull-request-number }}
run: |
echo "## Pull Request" >> $GITHUB_STEP_SUMMARY
echo "* Number - ${{ steps.cpr.outputs.pull-request-number }}" >> $GITHUB_STEP_SUMMARY
echo "* URL - [${{ steps.cpr.outputs.pull-request-url }}](${{ steps.cpr.outputs.pull-request-url }})" >> $GITHUB_STEP_SUMMARY