-
Notifications
You must be signed in to change notification settings - Fork 0
58 lines (53 loc) · 1.91 KB
/
template-get-update-version.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
name: get-update-version
on:
workflow_call:
outputs:
new_version:
description: 'The new version of the app'
value: ${{ jobs.get-update-version.outputs.new_version }}
jobs:
get-update-version:
runs-on: ubuntu-latest
environment: production
outputs:
new_version: ${{ steps.version_update.outputs.new_version }}
steps:
- name: Install jq
uses: dcarbone/[email protected]
- name: Get tag
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
id: tag
uses: dawidd6/action-get-tag@v1
- name: Update app version based on latest release tag with build number
id: version_update
run: |
# Function to get the latest release tag
get_latest_tag() {
local retries=0
local max_retries=3
local tag
while [ $retries -lt $max_retries ]; do
tag=$(curl -s https://api.github.com/repos/janhq/jan/releases/latest | jq -r .tag_name)
if [ -n "$tag" ] && [ "$tag" != "null" ]; then
echo $tag
return
else
let retries++
echo "Retrying... ($retries/$max_retries)"
sleep 2
fi
done
echo "Failed to fetch latest tag after $max_retries attempts."
exit 1
}
if ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') }}; then
echo "Tag detected, set output follow tag"
echo "::set-output name=new_version::${{ steps.tag.outputs.tag }}"
else
# Get the latest release tag from GitHub API
LATEST_TAG=$(get_latest_tag)
# Remove the 'v' and append the build number to the version
new_version="${LATEST_TAG#v}-${GITHUB_RUN_NUMBER}"
echo "New version: $new_version"
echo "::set-output name=new_version::$new_version"
fi