Skip to content

Commit 07fa648

Browse files
authored
Merge pull request #65 from github/version
Update Release + Versioning
2 parents dfbe3aa + 7f1894f commit 07fa648

File tree

7 files changed

+106
-7
lines changed

7 files changed

+106
-7
lines changed

__tests__/version.test.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import {VERSION} from '../src/version'
2+
3+
describe('VERSION constant', () => {
4+
const versionRegex = /^v(\d+)\.(\d+)\.(\d+)(?:-rc\.(\d+))?$/
5+
6+
it('should match the version pattern', () => {
7+
expect(VERSION).toMatch(versionRegex)
8+
})
9+
10+
it('should validate v1.0.0', () => {
11+
const version = 'v1.0.0'
12+
expect(version).toMatch(versionRegex)
13+
})
14+
15+
it('should validate v4.5.1', () => {
16+
const version = 'v4.5.1'
17+
expect(version).toMatch(versionRegex)
18+
})
19+
20+
it('should validate v10.123.44', () => {
21+
const version = 'v10.123.44'
22+
expect(version).toMatch(versionRegex)
23+
})
24+
25+
it('should validate v1.1.1-rc.1', () => {
26+
const version = 'v1.1.1-rc.1'
27+
expect(version).toMatch(versionRegex)
28+
})
29+
30+
it('should validate v15.19.4-rc.35', () => {
31+
const version = 'v15.19.4-rc.35'
32+
expect(version).toMatch(versionRegex)
33+
})
34+
})

dist/index.js

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

script/release

+41-6
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,58 @@ RED='\033[0;31m'
99
GREEN='\033[0;32m'
1010
BLUE='\033[0;34m'
1111

12-
latest_tag=$(git describe --tags $(git rev-list --tags --max-count=1))
13-
echo -e "The latest release tag is: ${BLUE}${latest_tag}${OFF}"
14-
read -p 'New Release Tag (vX.X.X format): ' new_tag
12+
# Read the version from src/version.js
13+
version_file="src/version.js"
14+
if [[ ! -f $version_file ]]; then
15+
echo -e "${RED}ERROR${OFF} - Version file not found: $version_file"
16+
exit 1
17+
fi
18+
19+
version_line=$(grep 'export const VERSION' $version_file)
20+
if [[ -z $version_line ]]; then
21+
echo -e "${RED}ERROR${OFF} - Version line not found in: $version_file"
22+
exit 1
23+
fi
24+
25+
# Extract the version value
26+
new_tag=$(echo $version_line | sed -E "s/export const VERSION = '([^']+)'/\1/")
27+
if [[ -z $new_tag ]]; then
28+
echo -e "${RED}ERROR${OFF} - Failed to extract version from: $version_file"
29+
exit 1
30+
fi
1531

16-
tag_regex='^v[0-9]+\.[0-9]+\.[0-9]+$'
17-
echo "$new_tag" | grep -E "$tag_regex"
32+
# Validate the version tag format
33+
tag_regex='^v[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$'
34+
echo "$new_tag" | grep -E "$tag_regex" > /dev/null
1835

1936
if [[ $? -ne 0 ]]; then
20-
echo -e "${RED}ERROR${OFF} - Tag: $new_tag is not valid. Please use vX.X.X format."
37+
echo -e "${RED}ERROR${OFF} - Tag: $new_tag is not valid. Please use vX.X.X or vX.X.X-rc.X format."
2138
exit 1
2239
fi
2340

41+
# Get the latest tag
42+
latest_tag=$(git describe --tags $(git rev-list --tags --max-count=1))
43+
echo -e "The latest release tag is: ${BLUE}${latest_tag}${OFF}"
44+
45+
# Confirm the new tag
46+
read -p "New Release Tag (press ENTER for default: ${new_tag}): " input_tag
47+
new_tag=${input_tag:-$new_tag}
48+
49+
# Tag the new release
2450
git tag -a $new_tag -m "$new_tag Release"
51+
if [[ $? -ne 0 ]]; then
52+
echo -e "${RED}ERROR${OFF} - Failed to create tag: $new_tag"
53+
exit 1
54+
fi
2555

2656
echo -e "${GREEN}OK${OFF} - Tagged: $new_tag"
2757

58+
# Push the tags to remote
2859
git push --tags
60+
if [[ $? -ne 0 ]]; then
61+
echo -e "${RED}ERROR${OFF} - Failed to push tags to remote"
62+
exit 1
63+
fi
2964

3065
echo -e "${GREEN}OK${OFF} - Tags pushed to remote!"
3166
echo -e "${GREEN}DONE${OFF}"

src/functions/post.js

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as github from '@actions/github'
44
import {context} from '@actions/github'
55
import {postReactions} from './post-reactions'
66
import {octokitRetry} from '@octokit/plugin-retry'
7+
import {VERSION} from '../version'
78

89
// Default failure reaction
910
const thumbsDown = '-1'
@@ -38,6 +39,7 @@ export async function post() {
3839

3940
// Create an octokit client with the retry plugin
4041
const octokit = github.getOctokit(token, {
42+
userAgent: `github/command@${VERSION}`,
4143
additionalPlugins: [octokitRetry]
4244
})
4345

src/main.js

+3
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ import {actionStatus} from './functions/action-status'
1010
import {prechecks} from './functions/prechecks'
1111
import {post} from './functions/post'
1212
import {COLORS} from './functions/colors'
13+
import {VERSION} from './version'
1314

1415
// :returns: 'success', 'failure', 'safe-exit' or raises an error
1516
export async function run() {
1617
try {
18+
core.info(`🛸 github/command ${COLORS.info}${VERSION}${COLORS.reset}`)
1719
// Get the inputs for the 'command' Action
1820
const command = core.getInput('command', {required: true})
1921
const token = core.getInput('github_token', {required: true})
@@ -26,6 +28,7 @@ export async function run() {
2628

2729
// create an octokit client with the retry plugin
2830
const octokit = github.getOctokit(token, {
31+
userAgent: `github/command@${VERSION}`,
2932
additionalPlugins: [octokitRetry]
3033
})
3134

src/version.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// The version of the command Action
2+
// Acceptable version formats:
3+
// - v1.0.0
4+
// - v4.5.1
5+
// - v10.123.44
6+
// - v1.1.1-rc.1
7+
// - etc
8+
9+
export const VERSION = 'v1.4.0'

0 commit comments

Comments
 (0)