Skip to content

Update Release + Versioning #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions __tests__/version.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {VERSION} from '../src/version'

describe('VERSION constant', () => {
const versionRegex = /^v(\d+)\.(\d+)\.(\d+)(?:-rc\.(\d+))?$/

it('should match the version pattern', () => {
expect(VERSION).toMatch(versionRegex)
})

it('should validate v1.0.0', () => {
const version = 'v1.0.0'
expect(version).toMatch(versionRegex)
})

it('should validate v4.5.1', () => {
const version = 'v4.5.1'
expect(version).toMatch(versionRegex)
})

it('should validate v10.123.44', () => {
const version = 'v10.123.44'
expect(version).toMatch(versionRegex)
})

it('should validate v1.1.1-rc.1', () => {
const version = 'v1.1.1-rc.1'
expect(version).toMatch(versionRegex)
})

it('should validate v15.19.4-rc.35', () => {
const version = 'v15.19.4-rc.35'
expect(version).toMatch(versionRegex)
})
})
16 changes: 16 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

47 changes: 41 additions & 6 deletions script/release
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,58 @@ RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'

latest_tag=$(git describe --tags $(git rev-list --tags --max-count=1))
echo -e "The latest release tag is: ${BLUE}${latest_tag}${OFF}"
read -p 'New Release Tag (vX.X.X format): ' new_tag
# Read the version from src/version.js
version_file="src/version.js"
if [[ ! -f $version_file ]]; then
echo -e "${RED}ERROR${OFF} - Version file not found: $version_file"
exit 1
fi

version_line=$(grep 'export const VERSION' $version_file)
if [[ -z $version_line ]]; then
echo -e "${RED}ERROR${OFF} - Version line not found in: $version_file"
exit 1
fi

# Extract the version value
new_tag=$(echo $version_line | sed -E "s/export const VERSION = '([^']+)'/\1/")
if [[ -z $new_tag ]]; then
echo -e "${RED}ERROR${OFF} - Failed to extract version from: $version_file"
exit 1
fi

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

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

# Get the latest tag
latest_tag=$(git describe --tags $(git rev-list --tags --max-count=1))
echo -e "The latest release tag is: ${BLUE}${latest_tag}${OFF}"

# Confirm the new tag
read -p "New Release Tag (press ENTER for default: ${new_tag}): " input_tag
new_tag=${input_tag:-$new_tag}

# Tag the new release
git tag -a $new_tag -m "$new_tag Release"
if [[ $? -ne 0 ]]; then
echo -e "${RED}ERROR${OFF} - Failed to create tag: $new_tag"
exit 1
fi

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

# Push the tags to remote
git push --tags
if [[ $? -ne 0 ]]; then
echo -e "${RED}ERROR${OFF} - Failed to push tags to remote"
exit 1
fi

echo -e "${GREEN}OK${OFF} - Tags pushed to remote!"
echo -e "${GREEN}DONE${OFF}"
2 changes: 2 additions & 0 deletions src/functions/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as github from '@actions/github'
import {context} from '@actions/github'
import {postReactions} from './post-reactions'
import {octokitRetry} from '@octokit/plugin-retry'
import {VERSION} from '../version'

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

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

Expand Down
3 changes: 3 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import {actionStatus} from './functions/action-status'
import {prechecks} from './functions/prechecks'
import {post} from './functions/post'
import {COLORS} from './functions/colors'
import {VERSION} from './version'

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

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

Expand Down
9 changes: 9 additions & 0 deletions src/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// The version of the command Action
// Acceptable version formats:
// - v1.0.0
// - v4.5.1
// - v10.123.44
// - v1.1.1-rc.1
// - etc

export const VERSION = 'v1.4.0'