Skip to content

Commit 6c80853

Browse files
author
Tuan Tran
committed
release: v0.0.1
1 parent ccc4597 commit 6c80853

File tree

8 files changed

+405
-201
lines changed

8 files changed

+405
-201
lines changed

actions/create-prod-tag/action.yml

Lines changed: 0 additions & 67 deletions
This file was deleted.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Create Production Tag
2+
description: "This action creates a tag on the release branch and optionally triggers a Jenkins build for that tag."
3+
4+
inputs:
5+
github-app-id:
6+
description: "GitHub App ID"
7+
required: true
8+
9+
github-private-key:
10+
description: "GitHub Private Key"
11+
required: true
12+
13+
use-jenkins-build:
14+
description: "Trigger Jenkins Build"
15+
required: false
16+
default: 'false'
17+
18+
jenkins-url:
19+
description: "Jenkins Server URL"
20+
required: false
21+
22+
jenkins-job-folder:
23+
description: "Jenkins Job Folder (Defaults to repository owner)"
24+
required: false
25+
default: ${{ github.repository_owner }}
26+
27+
jenkins-job-name:
28+
description: "Jenkins Job Name (Defaults to repository name)"
29+
required: false
30+
default: ${{ github.event.repository.name }}
31+
32+
jenkins-user:
33+
description: "Jenkins Username"
34+
required: false
35+
36+
jenkins-token:
37+
description: "Jenkins API Token"
38+
required: false
39+
40+
runs:
41+
using: "composite"
42+
steps:
43+
- name: Generate GitHub App Token
44+
uses: actions/create-github-app-token@v1
45+
id: github-app-token
46+
with:
47+
app-id: ${{ inputs.github-app-id }}
48+
private-key: ${{ inputs.github-private-key }}
49+
50+
- name: Checkout Source Code
51+
uses: actions/checkout@v4
52+
with:
53+
token: ${{ steps.github-app-token.outputs.token }}
54+
ref: ${{ github.head_ref }}
55+
56+
- name: Create Release Tag
57+
id: tag-release
58+
shell: bash
59+
run: |
60+
git config --global --add safe.directory /harness
61+
git config --global user.email "[email protected]"
62+
git config --global user.name "GitHub Actions"
63+
64+
chmod +x ${{ github.action_path }}/../../tools/create_tag.sh
65+
${{ github.action_path }}/../../tools/create_tag.sh
66+
env:
67+
GITHUB_TOKEN: ${{ steps.github-app-token.outputs.token }}
68+
69+
- name: Trigger Jenkins Build for Tag
70+
shell: bash
71+
if: ${{ inputs.use-jenkins-build == 'true' }}
72+
run: |
73+
chmod +x ${{ github.action_path }}/../../tools/jenkins_build_tag.sh
74+
${{ github.action_path }}/../../tools/jenkins_build_tag.sh \
75+
${{ inputs.jenkins-url }} \
76+
${{ inputs.jenkins-job-folder }} \
77+
${{ inputs.jenkins-job-name }} \
78+
${{ inputs.jenkins-user }} \
79+
${{ inputs.jenkins-token }} \
80+
${{ steps.tag-release.outputs.release_version }}

actions/cut-release-branch/action.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Cut Release Branch
2+
description: "Creates a release branch from the master branch if running on master, or syncs the given release branch with master."
3+
4+
inputs:
5+
github-app-id:
6+
description: "GitHub App ID"
7+
required: true
8+
9+
github-private-key:
10+
description: "GitHub Private Key"
11+
required: true
12+
13+
runs:
14+
using: "composite"
15+
steps:
16+
- name: Generate GitHub App Token
17+
uses: actions/create-github-app-token@v1
18+
id: github-app-token
19+
with:
20+
app-id: ${{ inputs.github-app-id }}
21+
private-key: ${{ inputs.github-private-key }}
22+
23+
- name: Checkout Source Code
24+
uses: actions/checkout@v4
25+
with:
26+
token: ${{ steps.github-app-token.outputs.token }}
27+
ref: ${{ github.head_ref }}
28+
29+
- name: Create or Sync Release Branch
30+
shell: bash
31+
run: |
32+
git config --global --add safe.directory /harness
33+
git config --global user.email "[email protected]"
34+
git config --global user.name "GitHub Actions"
35+
36+
chmod +x ${{env.GITHUB_ACTION_PATH}}/../../tools/cut_release.sh
37+
${{env.GITHUB_ACTION_PATH}}/../../tools/cut_release.sh "${{ github.event_name }}"
38+
env:
39+
GITHUB_TOKEN: ${{ steps.github-app-token.outputs.token }}
40+
GITHUB_ACTION_PATH: ${{ github.action_path }}

tools/bump_version.sh

Lines changed: 51 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,56 @@
11
#!/bin/bash
22

3-
# Get the current version from argument or use default
4-
CURRENT_VERSION=${1:-"v0.0.0"}
5-
BUMP_TYPE=${2:-"patch"} # Default to patch if not specified
6-
7-
# Extract the numeric version (remove 'v' prefix)
8-
VERSION_NUMBER=${CURRENT_VERSION#v}
9-
10-
# Split into major, minor, and patch
11-
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION_NUMBER"
12-
13-
# Increment the specified version part
14-
case "$BUMP_TYPE" in
15-
"patch")
16-
PATCH=$((PATCH + 1))
17-
;;
18-
"minor")
19-
MINOR=$((MINOR + 1))
20-
PATCH=0 # Reset patch when bumping minor
21-
;;
22-
"major")
23-
MAJOR=$((MAJOR + 1))
24-
MINOR=0 # Reset minor when bumping major
25-
PATCH=0 # Reset patch when bumping major
26-
;;
27-
*)
28-
echo "Invalid bump type. Use 'patch', 'minor', or 'major'."
3+
set -euo pipefail # Exit on error, unset variables, or failed piped commands
4+
5+
# Function to extract and split the version number
6+
extract_version_parts() {
7+
local version="$1"
8+
local version_number="${version#v}" # Remove 'v' prefix if present
9+
10+
# Validate version format (must be numeric X.Y.Z)
11+
if ! [[ "$version_number" =~ ^[0-9]+(\.[0-9]+){2}$ ]]; then
12+
echo "❌ Error: Invalid version format '$version'. Expected 'vX.Y.Z' or 'X.Y.Z'." >&2
2913
exit 1
30-
;;
31-
esac
14+
fi
15+
16+
IFS='.' read -r MAJOR MINOR PATCH <<< "$version_number"
17+
}
18+
19+
# Function to increment the version based on bump type
20+
bump_version() {
21+
local bump_type="$1"
22+
23+
case "$bump_type" in
24+
"patch")
25+
PATCH=$((PATCH + 1))
26+
;;
27+
"minor")
28+
MINOR=$((MINOR + 1))
29+
PATCH=0 # Reset patch when bumping minor
30+
;;
31+
"major")
32+
MAJOR=$((MAJOR + 1))
33+
MINOR=0 # Reset minor when bumping major
34+
PATCH=0 # Reset patch when bumping major
35+
;;
36+
*)
37+
echo "❌ Error: Invalid bump type '$bump_type'. Use 'patch', 'minor', or 'major'." >&2
38+
exit 1
39+
;;
40+
esac
41+
}
42+
43+
# Main script execution
44+
main() {
45+
local current_version="${1:-"v0.0.0"}"
46+
local bump_type="${2:-"patch"}" # Default to "patch" if not specified
47+
48+
extract_version_parts "$current_version"
49+
bump_version "$bump_type"
3250

33-
# Construct the new version
34-
NEW_VERSION="v$MAJOR.$MINOR.$PATCH"
51+
# Should be the last line, the output
52+
echo "v$MAJOR.$MINOR.$PATCH"
53+
}
3554

36-
# Output the new version
37-
echo "$NEW_VERSION"
55+
# Run the script
56+
main "$@"

tools/create_release.sh

Lines changed: 0 additions & 32 deletions
This file was deleted.

tools/create_tag.sh

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail # Exit on error, unset variables, or failed piped commands
4+
5+
# Function to check requirements
6+
check_requirements() {
7+
echo "🔍 Checking system requirements..."
8+
if ! command -v jq &>/dev/null; then
9+
echo "❌ Error: jq is not installed." >&2
10+
exit 1
11+
fi
12+
echo "✅ All requirements are met."
13+
}
14+
15+
# Function to validate the current branch
16+
validate_branch() {
17+
local branch
18+
branch="$(git rev-parse --abbrev-ref HEAD)"
19+
20+
if [[ ! $branch =~ ^release/.*$ ]]; then
21+
echo "❌ Error: Releasing PROD must be done from a release branch." >&2
22+
exit 1
23+
fi
24+
echo "✅ Valid branch detected: $branch"
25+
}
26+
27+
# Function to get the current version from manifest.json
28+
get_version() {
29+
if [[ ! -f "manifest.json" ]]; then
30+
echo "❌ Error: manifest.json not found!" >&2
31+
exit 1
32+
fi
33+
34+
jq -r '.version' "manifest.json"
35+
}
36+
37+
# Function to delete an existing tag if it exists
38+
delete_existing_tag() {
39+
local version="$1"
40+
41+
if git rev-parse "refs/tags/$version" >/dev/null 2>&1; then
42+
echo "⚠️ Tag $version already exists. Deleting..."
43+
git tag -d "$version"
44+
git push --delete origin "$version" || echo "⚠️ Warning: Could not delete tag $version from remote."
45+
echo "✅ Deleted existing tag: $version"
46+
fi
47+
}
48+
49+
# Function to create and push a new tag
50+
create_and_push_tag() {
51+
local version="$1"
52+
53+
echo "🏷️ Creating and pushing tag: $version"
54+
git tag "$version"
55+
git push origin "$version"
56+
echo "🎉 Tag $version created and pushed successfully."
57+
58+
# Output release version for GitHub Actions
59+
echo "release_version=$version" >> "$GITHUB_OUTPUT"
60+
}
61+
62+
# Main script execution
63+
main() {
64+
check_requirements
65+
validate_branch
66+
67+
local version
68+
version=$(get_version)
69+
70+
delete_existing_tag "$version"
71+
create_and_push_tag "$version"
72+
}
73+
74+
main "$@"

0 commit comments

Comments
 (0)