-
Notifications
You must be signed in to change notification settings - Fork 2
93 lines (75 loc) · 2.85 KB
/
main.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
name: Bump version and Release
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: '0'
- name: Display current style.css before update
run: cat style.css
- name: Bump version in style.css
id: bump_version
run: |
# Read the current version from style.css
current_version=$(grep -oP 'Version:\s*\K[0-9.]+' style.css)
echo "Current version: $current_version"
# Split the version into an array
IFS='.' read -r -a version_parts <<< "$current_version"
# Increment the last part of the version
version_parts[-1]=$((version_parts[-1] + 1))
# Join the parts back into a new version string
new_version="${version_parts[*]}"
new_version="${new_version// /.}"
# Update the version in style.css using awk
awk -v new_version="$new_version" '{
if ($1 == "Version:") {
$2 = new_version
}
print
}' style.css > style.css.tmp && mv style.css.tmp style.css
# Verify the update
updated_version=$(grep -oP 'Version:\s*\K[0-9.]+' style.css)
echo "Updated version: $updated_version"
if [ "$updated_version" != "$new_version" ]; then
echo "Version update failed"
exit 1
fi
# Output the new version
echo "new_version=$new_version" >> $GITHUB_ENV
- name: Display current style.css after update
run: cat style.css
- name: Commit changes
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add style.css
git commit -m "Bump version to ${{ env.new_version }}"
git push
- name: Create new GitHub tag
run: |
git tag -a "v${{ env.new_version }}" -m "Version ${{ env.new_version }}"
git push origin "v${{ env.new_version }}"
- name: Create zip file of the repository
run: |
shopt -s extglob # Enable extended globbing
mkdir snn-brx-child-theme
mv !(.git|*.github*|snn-brx-child-theme) snn-brx-child-theme/
zip -r snn-brx-child-theme.zip snn-brx-child-theme -x "*.git*" "*.github*"
shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
new_version: ${{ env.new_version }}
- name: Create GitHub release
uses: softprops/action-gh-release@v1
with:
files: snn-brx-child-theme.zip
tag_name: ${{ env.new_version }}
release_name: Release ${{ env.new_version }}
body: "Version ${{ env.new_version }} release of the project."
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}