-
Notifications
You must be signed in to change notification settings - Fork 0
168 lines (156 loc) · 6.21 KB
/
Copy pathsemantic-release.yml
File metadata and controls
168 lines (156 loc) · 6.21 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
name: Prepare Version
on:
workflow_call:
secrets:
RELEASE_TOKEN:
required: false
APP_ID:
required: false
APP_PRIVATE_KEY:
required: false
inputs:
default_version:
description: 'Default version if no input is provided'
required: false
default: 'dev'
type: string
version_override:
description: 'Explicit version override (e.g. from workflow_dispatch)'
required: false
default: ''
type: string
ref:
description: 'Git ref to checkout'
required: false
default: ''
type: string
dry_run:
description: 'Run semantic-release in dry-run mode (no tag/release/changelog)'
required: false
default: false
type: boolean
runner:
description: 'Runner to use for the job'
required: false
default: 'self-hosted'
type: string
outputs:
commit_hash:
description: 'Short commit hash'
value: ${{ jobs.prepare.outputs.commit_hash }}
git_branch:
description: 'Git branch name'
value: ${{ jobs.prepare.outputs.git_branch }}
build_timestamp:
description: 'Build timestamp in ISO 8601'
value: ${{ jobs.prepare.outputs.build_timestamp }}
version:
description: 'Resolved version string (semver if released, otherwise default/override)'
value: ${{ jobs.prepare.outputs.version }}
is_release:
description: 'Whether semantic-release created a new release'
value: ${{ jobs.prepare.outputs.is_release }}
semver:
description: 'Semver version without v prefix (e.g. 1.0.0), empty if no release'
value: ${{ jobs.prepare.outputs.semver }}
jobs:
prepare:
runs-on: ${{ inputs.runner }}
permissions:
contents: write
packages: write
issues: write
pull-requests: write
outputs:
commit_hash: ${{ steps.version.outputs.commit_hash }}
git_branch: ${{ steps.version.outputs.git_branch }}
build_timestamp: ${{ steps.version.outputs.build_timestamp }}
version: ${{ steps.version.outputs.version }}
is_release: ${{ steps.version.outputs.is_release }}
semver: ${{ steps.version.outputs.semver }}
steps:
- name: Validate auth configuration
id: auth-check
env:
RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }}
APP_ID: ${{ secrets.APP_ID }}
APP_PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }}
run: |
if [ -n "${APP_ID}" ] && [ -n "${APP_PRIVATE_KEY}" ]; then
echo "use_app_auth=true" >> $GITHUB_OUTPUT
elif [ -n "${RELEASE_TOKEN}" ]; then
echo "use_app_auth=false" >> $GITHUB_OUTPUT
else
echo "::error::Either RELEASE_TOKEN or both APP_ID and APP_PRIVATE_KEY must be set"
exit 1
fi
- name: Generate a token
id: generate-token
if: steps.auth-check.outputs.use_app_auth == 'true'
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
with:
client-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: ${{ github.event.repository.name }}
- name: Checkout repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0.0.2
with:
ref: ${{ inputs.ref || github.ref }}
# token: ${{ secrets.GITHUB_TOKEN }}
token: ${{ steps.generate-token.outputs.token || secrets.RELEASE_TOKEN }}
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: 22
- name: Semantic Release
id: semantic
uses: cycjimmy/semantic-release-action@b12c8f6015dc215fe37bc154d4ad456dd3833c90 # v6.0.0
with:
dry_run: ${{ inputs.dry_run }}
extra_plugins: |
@semantic-release/changelog
@semantic-release/git
env:
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token || secrets.RELEASE_TOKEN }}
GITHUB_NPM_TOKEN: ${{ steps.generate-token.outputs.token || secrets.RELEASE_TOKEN }}
- name: Get version info
id: version
run: |
COMMIT_HASH=$(git rev-parse --short HEAD)
GIT_BRANCH=${GITHUB_REF_NAME}
BUILD_TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
# Check if semantic-release published a new version
NEW_RELEASE="${{ steps.semantic.outputs.new_release_published }}"
SEMVER="v${{ steps.semantic.outputs.new_release_version }}"
if [ "${NEW_RELEASE}" == "true" ]; then
IS_RELEASE="true"
else
IS_RELEASE="false"
SEMVER=""
fi
# Priority: version_override > semantic-release version > default_version
if [ -n "${{ inputs.version_override }}" ]; then
VERSION="${{ inputs.version_override }}"
elif [ "${IS_RELEASE}" == "true" ]; then
VERSION="${SEMVER}"
else
VERSION="${{ inputs.default_version }}"
fi
echo "commit_hash=${COMMIT_HASH}" >> $GITHUB_OUTPUT
echo "git_branch=${GIT_BRANCH}" >> $GITHUB_OUTPUT
echo "build_timestamp=${BUILD_TIMESTAMP}" >> $GITHUB_OUTPUT
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "is_release=${IS_RELEASE}" >> $GITHUB_OUTPUT
echo "semver=${SEMVER}" >> $GITHUB_OUTPUT
echo "## Version Info" >> $GITHUB_STEP_SUMMARY
echo "| Key | Value |" >> $GITHUB_STEP_SUMMARY
echo "|-----|-------|" >> $GITHUB_STEP_SUMMARY
echo "| Version | ${VERSION} |" >> $GITHUB_STEP_SUMMARY
echo "| Semver | ${SEMVER:-n/a} |" >> $GITHUB_STEP_SUMMARY
echo "| New Release | ${IS_RELEASE} |" >> $GITHUB_STEP_SUMMARY
echo "| Release Type | ${{ steps.semantic.outputs.new_release_type }} |" >> $GITHUB_STEP_SUMMARY
echo "| Commit | ${COMMIT_HASH} |" >> $GITHUB_STEP_SUMMARY
echo "| Branch | ${GIT_BRANCH} |" >> $GITHUB_STEP_SUMMARY
echo "| Timestamp | ${BUILD_TIMESTAMP} |" >> $GITHUB_STEP_SUMMARY