-
-
Notifications
You must be signed in to change notification settings - Fork 2
122 lines (106 loc) · 4.27 KB
/
Copy pathrelease.yml
File metadata and controls
122 lines (106 loc) · 4.27 KB
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
name: Plugin Release
on:
push:
branches:
- main
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: '0'
- name: Get current version
id: get_version
run: |
version=$(grep -oP 'Version:\s*\K[0-9.]+' github-to-wordpress-sync.php)
echo "Current version: $version"
echo "version=$version" >> $GITHUB_ENV
- name: Bump version if release
if: contains(github.event.head_commit.message, 'release')
run: |
current_version=$(grep -oP 'Version:\s*\K[0-9.]+' github-to-wordpress-sync.php)
next_version=$(awk -F. '{print $1 "." ($2+1)}' <<< "$current_version")
sed -i "s/Version: $current_version/Version: $next_version/" github-to-wordpress-sync.php
echo "new_version=$next_version" >> $GITHUB_ENV
- name: Commit version bump
if: contains(github.event.head_commit.message, 'release')
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add github-to-wordpress-sync.php
git commit -m "Bump version to ${{ env.new_version }}"
git push
- name: Create zip file
run: |
mkdir -p github-to-wordpress-sync
rsync -av --exclude='.git' --exclude='.github' --exclude='github-to-wordpress-sync' ./ github-to-wordpress-sync/
zip -r github-to-wordpress-sync.zip github-to-wordpress-sync
rm -rf github-to-wordpress-sync
- name: Generate changelog
if: contains(github.event.head_commit.message, 'release')
id: changelog
run: |
# Get the previous release tag
previous_tag=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -z "$previous_tag" ]; then
# If no previous tag, get all commits
changelog=$(git log --pretty=format:"- %s (%h)")
else
# Get commits since previous tag
changelog=$(git log ${previous_tag}..HEAD --pretty=format:"- %s (%h)")
fi
# Create the release body
{
echo "## What's Changed"
echo ""
echo "$changelog"
echo ""
if [ -n "$previous_tag" ]; then
echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/${previous_tag}...v${{ env.new_version }}"
fi
} > release_notes.md
# Set output for use in next step
echo "previous_tag=$previous_tag" >> $GITHUB_ENV
- name: Create GitHub Release
if: contains(github.event.head_commit.message, 'release')
uses: softprops/action-gh-release@v1
with:
files: github-to-wordpress-sync.zip
tag_name: "v${{ env.new_version }}"
name: "Release v${{ env.new_version }}"
body_path: release_notes.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Generate pre-release changelog
if: contains(github.event.head_commit.message, 'alphatag')
run: |
# Get the previous tag
previous_tag=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -z "$previous_tag" ]; then
changelog=$(git log --pretty=format:"- %s (%h)")
else
changelog=$(git log ${previous_tag}..HEAD --pretty=format:"- %s (%h)")
fi
{
echo "## What's Changed (Pre-release)"
echo ""
echo "$changelog"
echo ""
if [ -n "$previous_tag" ]; then
echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/${previous_tag}...pre-v${{ env.version }}"
fi
} > prerelease_notes.md
- name: Create GitHub Pre-release
if: contains(github.event.head_commit.message, 'alphatag')
uses: softprops/action-gh-release@v1
with:
prerelease: true
files: github-to-wordpress-sync.zip
tag_name: "pre-v${{ env.version }}"
name: "Pre-release v${{ env.version }}"
body_path: prerelease_notes.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}