-
Notifications
You must be signed in to change notification settings - Fork 0
131 lines (114 loc) · 3.92 KB
/
release.yml
File metadata and controls
131 lines (114 loc) · 3.92 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
123
124
125
126
127
128
129
130
131
name: Bump version and release
on:
workflow_dispatch:
inputs:
bump:
description: "Select version bump type?"
required: true
default: "patch"
type: choice
options:
- major
- minor
- patch
env:
VENDOR: Sviat
MODULE: OrderManagerControl
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get latest tag
id: get_tag
run: |
last_tag=$(git describe --tags --abbrev=0 || echo "v0.0.0")
echo "last_tag=$last_tag" >> $GITHUB_OUTPUT
- name: Bump version
id: bump
run: |
last=${{ steps.get_tag.outputs.last_tag }}
bump=${{ github.event.inputs.bump }}
ver=${last#v}
major=$(echo $ver | cut -d. -f1)
minor=$(echo $ver | cut -d. -f2)
patch=$(echo $ver | cut -d. -f3)
case $bump in
major)
major=$((major+1))
minor=0
patch=0
;;
minor)
minor=$((minor+1))
patch=0
;;
patch)
patch=$((patch+1))
;;
esac
new_tag="v$major.$minor.$patch"
echo "new_tag=$new_tag" >> $GITHUB_OUTPUT
- name: Set build variables
id: vars
run: |
echo "module_path=${{ env.VENDOR }}/${{ env.MODULE }}" >> $GITHUB_OUTPUT
echo "zip_name=${{ env.MODULE }}-${{ steps.bump.outputs.new_tag }}.zip" >> $GITHUB_OUTPUT
- name: Check for changes since last tag
run: |
LAST_TAG=${{ steps.get_tag.outputs.last_tag }}
if [ "$LAST_TAG" != "v0.0.0" ] && [ "$(git rev-parse $LAST_TAG)" = "$(git rev-parse HEAD)" ]; then
echo "No new commits since $LAST_TAG. Aborting."
exit 1
fi
- name: Create new tag
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
NEW_TAG=${{ steps.bump.outputs.new_tag }}
if git rev-parse "$NEW_TAG" >/dev/null 2>&1; then
echo "Tag $NEW_TAG already exists. Deleting it."
git tag -d "$NEW_TAG"
git push origin --delete "$NEW_TAG" || true
fi
git tag "$NEW_TAG"
git push origin "$NEW_TAG"
- name: Build module archive
run: |
mkdir -p dist
mkdir -p temp_build/${{ steps.vars.outputs.module_path }}
rsync -av \
--exclude='.github' \
--exclude='.gitignore' \
--exclude='README.md' \
--exclude='temp_build' \
--exclude='dist' \
--exclude='.git' \
./ temp_build/${{ steps.vars.outputs.module_path }}/
cd temp_build
zip -r ../dist/${{ steps.vars.outputs.zip_name }} ${{ steps.vars.outputs.module_path }}
cd ..
rm -rf temp_build
- name: Delete existing release if it exists
run: |
TAG=${{ steps.bump.outputs.new_tag }}
RELEASE_ID=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/releases/tags/$TAG | jq .id)
if [ "$RELEASE_ID" != "null" ]; then
curl -s -X DELETE -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/releases/$RELEASE_ID
fi
- name: Create GitHub release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.bump.outputs.new_tag }}
name: Release ${{ steps.bump.outputs.new_tag }}
generate_release_notes: true
files: dist/${{ steps.vars.outputs.zip_name }}
fail_on_unmatched_files: false
draft: false
prerelease: false