-
Notifications
You must be signed in to change notification settings - Fork 2
105 lines (89 loc) · 3.39 KB
/
ci-auto-release.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
name: Automated Release
on:
schedule:
- cron: "0 12 1 * *" # At 12:00 on day-of-month 1
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
# Check if the event is not triggered by a fork
# if: ${{ github.repository == 'p4lang/p4c' && github.ref == 'refs/heads/main' }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# Fetch all history for all branches and tags
fetch-depth: 0
- name: Increment version number
run: perl -i -pe 's/\b(\d+)(?=\D*$)/$1+1/e' Version.txt
- name: Get changelog
id: changelog
run: |
TAG="$(git describe --tags --abbrev=0)"
GIT_LOG="$(git log $TAG..HEAD --oneline --pretty=format:"- %s [%an]")"
CHANGELOG=$(cat << EOF
Changelog:
$GIT_LOG
EOF
)
CHANGELOG="${CHANGELOG//'%'/'%25'}"
CHANGELOG="${CHANGELOG//$'\n'/'%0A'}"
CHANGELOG="${CHANGELOG//$'\r'/'%0D'}"
CHANGELOG="${CHANGELOG//'#'/''}"
echo "::set-output name=content::$CHANGELOG"
- name: Display changelog
run: echo "${{ steps.changelog.outputs.content }}"
- name: Get version
run: |
VERSION="$(cat Version.txt)"
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Update changelog.md
run: |
# Define the new changelog content
NEW_CHANGELOG="## Version v${{ env.VERSION }}\n\n${{ steps.changelog.outputs.content }}\n"
# Insert new changelog before the first release section
awk -v new_changelog="$NEW_CHANGELOG" '/^## Release /{print new_changelog; new_changelog="";} 1' changelog.md > temp && mv temp changelog.md
- name: Commit and push changelog
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add changelog.md Version.txt
git commit -m "Update changelog and bump version to v${{ env.VERSION }}"
git push origin main
- name: Get commit message
id: message
run: |
COMMIT_MSG=$(cat << EOF
Release v${{ env.VERSION }}
${{ steps.changelog.outputs.content }}
EOF
)
COMMIT_MSG="${COMMIT_MSG//'%'/'%25'}"
COMMIT_MSG="${COMMIT_MSG//$'\n'/'%0A'}"
COMMIT_MSG="${COMMIT_MSG//$'\r'/'%0D'}"
echo "::set-output name=content::$COMMIT_MSG"
- name: Get pull request body message
id: body
run: |
MSG=$(cat << EOF
Auto-generated pull request for version ${{ env.VERSION }}.
Please use **Squash and merge** to include the changelog in the release message.
${{ steps.changelog.outputs.content }}
EOF
)
MSG="${MSG//'%'/'%25'}"
MSG="${MSG//$'\n'/'%0A'}"
MSG="${MSG//$'\r'/'%0D'}"
echo "::set-output name=content::$MSG"
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
base: main
add-paths: Version.txt changelog.md
reviewers: mbudiu-vmw
commit-message: ${{ steps.message.outputs.content }}
signoff: false
branch: v${{ env.VERSION }}
delete-branch: true
title: Automated Release v${{ env.VERSION }}
body: ${{ steps.body.outputs.content }}