Skip to content

Commit af6b939

Browse files
lucydodoharveyrendell
authored andcommitted
Add the option to take new custom version for Snapshot (getredash#7096)
1 parent b52f381 commit af6b939

File tree

2 files changed

+61
-5
lines changed

2 files changed

+61
-5
lines changed
Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
name: Periodic Snapshot
22

3-
# 10 minutes after midnight on the first of every month
43
on:
54
schedule:
6-
- cron: '10 0 1 * *'
5+
- cron: '10 0 1 * *' # 10 minutes after midnight on the first of every month
6+
workflow_dispatch:
7+
inputs:
8+
bump:
9+
description: 'Bump the last digit of the version'
10+
required: false
11+
type: boolean
12+
version:
13+
description: 'Specific version to set'
14+
required: false
15+
default: ''
16+
17+
env:
18+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
719

820
permissions:
21+
actions: write
922
contents: write
1023

1124
jobs:
@@ -14,17 +27,59 @@ jobs:
1427
steps:
1528
- uses: actions/checkout@v4
1629
with:
17-
ssh-key: ${{secrets.ACTION_PUSH_KEY}}
30+
ssh-key: ${{ secrets.ACTION_PUSH_KEY }}
31+
1832
- run: |
19-
# https://api.github.com/users/github-actions[bot]
2033
git config user.name 'github-actions[bot]'
2134
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
2235
23-
TAG_NAME="$(date +%y.%m).0-dev"
36+
# Function to bump the version
37+
bump_version() {
38+
local version="$1"
39+
local IFS=.
40+
read -r major minor patch <<< "$version"
41+
patch=$((patch + 1))
42+
echo "$major.$minor.$patch-dev"
43+
}
44+
45+
# Determine the new version tag
46+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
47+
BUMP_INPUT="${{ github.event.inputs.bump }}"
48+
SPECIFIC_VERSION="${{ github.event.inputs.version }}"
49+
50+
# Check if both bump and specific version are provided
51+
if [ "$BUMP_INPUT" = "true" ] && [ -n "$SPECIFIC_VERSION" ]; then
52+
echo "::error::Error: Cannot specify both bump and specific version."
53+
exit 1
54+
fi
55+
56+
if [ -n "$SPECIFIC_VERSION" ]; then
57+
TAG_NAME="$SPECIFIC_VERSION-dev"
58+
elif [ "$BUMP_INPUT" = "true" ]; then
59+
CURRENT_VERSION=$(grep '"version":' package.json | awk -F\" '{print $4}')
60+
TAG_NAME=$(bump_version "$CURRENT_VERSION")
61+
else
62+
echo "No version bump or specific version provided for manual dispatch."
63+
exit 1
64+
fi
65+
else
66+
TAG_NAME="$(date +%y.%m).0-dev"
67+
fi
68+
69+
echo "New version tag: $TAG_NAME"
70+
71+
# Update version in files
2472
gawk -i inplace -F: -v q=\" -v tag=${TAG_NAME} '/^ "version": / { print $1 FS, q tag q ","; next} { print }' package.json
2573
gawk -i inplace -F= -v q=\" -v tag=${TAG_NAME} '/^__version__ =/ { print $1 FS, q tag q; next} { print }' redash/__init__.py
2674
gawk -i inplace -F= -v q=\" -v tag=${TAG_NAME} '/^version =/ { print $1 FS, q tag q; next} { print }' pyproject.toml
75+
2776
git add package.json redash/__init__.py pyproject.toml
2877
git commit -m "Snapshot: ${TAG_NAME}"
2978
git tag ${TAG_NAME}
3079
git push --atomic origin master refs/tags/${TAG_NAME}
80+
81+
# Run the 'preview-image' workflow if run this workflow manually
82+
# For more information, please see the: https://docs.github.com/en/actions/security-guides/automatic-token-authentication
83+
if [ "$BUMP_INPUT" = "true" ] || [ -n "$SPECIFIC_VERSION" ]; then
84+
gh workflow run preview-image.yml --ref $TAG_NAME
85+
fi

.github/workflows/preview-image.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ on:
33
push:
44
tags:
55
- '*-dev'
6+
workflow_dispatch:
67

78
env:
89
NODE_VERSION: 18

0 commit comments

Comments
 (0)