-
Notifications
You must be signed in to change notification settings - Fork 445
88 lines (76 loc) · 2.69 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
name: Automated Release
on:
schedule:
- cron: "0 12 1 * *" # At 12:00 on day-of-month 1
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: Get commit message
id: message
run: |
COMMIT_MSG=$(cat << EOF
Release v${{ env.VERSION }}
Signed-off-by: rst0git <[email protected]>
${{ 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@v7
with:
base: main
add-paths: Version.txt
reviewers: fruffy, jafingerhut, jnfoster
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 }}