generated from rubrion/rubrion-cli-template
-
Notifications
You must be signed in to change notification settings - Fork 0
123 lines (107 loc) · 4.2 KB
/
deploy.yml
File metadata and controls
123 lines (107 loc) · 4.2 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
name: Production Release Pipeline
on:
workflow_dispatch:
inputs:
release_version:
description: "Enter version (e.g., 1.2.3). Leave empty for auto patch bump."
required: false
default: ""
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Create GitHub App Token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ vars.RUBRION_APP_ID }}
private-key: ${{ secrets.RUBRION_APP_SECRET }}
- name: Set Git User Identity
run: |
git config --global user.name "Rubrion"
git config --global user.email "rubrion[bot]@users.noreply.github.com"
- name: Checkout Develop Branch
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: develop
token: ${{ steps.app-token.outputs.token }}
- name: Ensure Develop is Up to Date
run: |
git fetch origin develop
git checkout develop
git pull origin develop
- name: Determine Release Version
id: version
run: |
if [ -n "${{ github.event.inputs.release_version }}" ]; then
VERSION=${{ github.event.inputs.release_version }}
else
LAST_TAG=$(git tag --sort=-v:refname | head -n 1 | sed 's/v//')
IFS='.' read -r major minor patch <<< "$LAST_TAG"
VERSION="$major.$minor.$((patch + 1))"
fi
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "Release version set to $VERSION"
- name: Check if Main Branch Exists and Merge
run: |
if git ls-remote --heads origin main | grep main; then
echo "Main branch exists, proceeding with merge"
git checkout main || git checkout -b main
git merge --no-ff develop -m "chore: merge develop into main for release v${VERSION}"
else
echo "Main branch does not exist, creating from develop"
git checkout -b main
fi
git push -u origin main
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Verify Version in Code
run: |
VERSION_IN_CODE=$(grep "CurrentVersion =" internal/commands/version.go | awk -F'"' '{print $2}')
echo "Version in code: $VERSION_IN_CODE"
echo "Expected version: $VERSION"
if [ "$VERSION_IN_CODE" != "$VERSION" ]; then
echo "ERROR: Version mismatch detected!"
echo "The version in internal/commands/version.go ($VERSION_IN_CODE) does not match the release version ($VERSION)."
echo "Please update the CurrentVersion in internal/commands/version.go to $VERSION and run the workflow again."
exit 1
else
echo "Version check passed: Code version matches release version."
fi
- name: Generate Changelog
run: |
npx conventional-changelog-cli -p angular -o docs/CHANGELOG.md
git add docs/CHANGELOG.md
git commit -m "docs: release v${VERSION} [skip ci]"
git push origin main
- name: Create Git Tag
run: |
git tag "v${VERSION}"
git push origin --tags
- name: Set Up Go
uses: actions/setup-go@v5
with:
go-version: 1.23
- name: Build Cross-Platform Binaries
run: |
if [ -z "${{ vars.PROJECT_NAME }}" ]; then
echo "ERROR: PROJECT_NAME GitHub variable is not set. Please set it in repository settings."
exit 1
fi
PROJECT_NAME="${{ vars.PROJECT_NAME }}"
echo "Using project name: $PROJECT_NAME"
go mod tidy
echo "Building CLI for version $VERSION"
make build-all VERSION=$VERSION
- name: Create GitHub Release
run: |
PROJECT_NAME="${{ vars.PROJECT_NAME }}"
gh release create "v${VERSION}" \
--title "Release v${VERSION}" \
--notes-file docs/CHANGELOG.md \
dist/$PROJECT_NAME-linux dist/$PROJECT_NAME.exe dist/$PROJECT_NAME-mac
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}