forked from LimeChain/Fruzhin
-
Notifications
You must be signed in to change notification settings - Fork 0
161 lines (142 loc) · 4.64 KB
/
tag-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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
name: Create & Release
on:
workflow_dispatch:
inputs:
tag_name:
description: 'Tag name (e.g. v1.0.0)'
required: true
default: 'v1.0.0'
github_release:
description: 'GitHub release?'
required: true
type: boolean
default: true
npm_release:
description: 'NPM release?'
required: true
type: boolean
default: true
jobs:
shared-steps:
name: Run shared steps
runs-on: ubuntu-latest
steps:
- name: Check tag format
run: |
TAG_NAME=${{ github.event.inputs.tag_name }}
if [[ ! "$TAG_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid tag format: $TAG_NAME. Must follow v[0-9]+.[0-9]+.[0-9]+"
exit 1
else
echo "Valid tag format: $TAG_NAME"
fi
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: dev
- name: Create or use provided tag
run: |
# Use provided tag from the input
NEW_TAG=${{ github.event.inputs.tag_name }}
echo "Tag name: $NEW_TAG"
git tag $NEW_TAG
git push origin $NEW_TAG
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
github-release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: shared-steps
if: ${{ github.event.inputs.github_release == 'true' }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.tag_name }}
- name: Build Changelog
id: changelog
continue-on-error: true
uses: requarks/changelog-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
token: ${{ github.token }}
tag: ${{ github.event.inputs.tag_name }}
- name: Write release version
run: |
VERSION=${{ github.event.inputs.tag_name }}
echo "Releasing version: $VERSION"
sed -i -e 's@version = .\d*.\d*.\d*.*@version = "'"$VERSION"'"@g' build.gradle.kts
- name: Set up cache for Gradle
uses: actions/cache@v4
with:
path: ~/.gradle/caches
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
gradle-${{ runner.os }}
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'corretto'
- name: Build Gradle Project
run: ./gradlew build
- name: Create release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.event.inputs.tag_name }}
release_name: Release ${{ github.event.inputs.tag_name }}
body: ${{ steps.changelog.outputs.changes || 'No changelog available' }}
draft: false
prerelease: false
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./build/libs/Fruzhin-${{ github.event.inputs.tag_name }}.war
asset_name: Fruzhin-${{ github.event.inputs.tag_name }}.war
asset_content_type: application/x-zip
npm-release:
name: Publish to NPM
runs-on: ubuntu-latest
needs: shared-steps
if: ${{ github.event.inputs.npm_release == 'true' }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.tag_name }}
- name: Set up cache for Gradle
uses: actions/cache@v4
with:
path: ~/.gradle/caches
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
gradle-${{ runner.os }}
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'corretto'
- name: Build Gradle Project
run: ./gradlew build
- name: Unzip WAR file
run: |
ls -l
unzip ./build/libs/*.war -d dist
rm -rf ./dist/META-INF ./dist/WEB-INF ./dist/index.html
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: "https://registry.npmjs.org"
- name: Publish to NPM
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm publish