Skip to content

Commit dcc54ea

Browse files
committed
Added release workflow dispatch
1 parent e97358c commit dcc54ea

File tree

3 files changed

+128
-32
lines changed

3 files changed

+128
-32
lines changed

.github/workflows/release.yml

+125-29
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ name: XVM Release Workflow
99
on:
1010
workflow_dispatch: # Allows manual triggering from GitHub Actions UIon:
1111
inputs:
12-
trigger_manual_release:
13-
type: choice
12+
branch:
13+
description: 'Branch to release from'
14+
default: 'simplify-tasks' # TODO: Change to master
1415
required: true
15-
default: 'false'
16-
options:
17-
- 'true'
18-
- 'false'
19-
description: Trigger a manual release
16+
version:
17+
description: 'Overriding version for the release'
18+
default: ''
19+
required: false
2020
#push:
2121
# TODO let the xvm-build-verify action ensure release tags too. It should already be doing that.
2222
#tags:
@@ -37,41 +37,71 @@ jobs:
3737
os: [ubuntu-latest, windows-latest, macos-latest]
3838

3939
steps:
40-
- name: Checkout Repository
41-
uses: actions/checkout@v4
42-
with:
43-
show-progress: true
44-
fetch-depth: 0 # Full depth for accurate tags
4540
- name: Setup Java
4641
uses: actions/setup-java@v4
4742
with:
4843
distribution: zulu
4944
java-version: 21
45+
- name: Setup GitHub CLI (if necessary)
46+
shell: bash
47+
run: |
48+
if ! command -v gh &> /dev/null; then
49+
echo "Installing GitHub CLI..."
50+
sudo apt-get update
51+
sudo apt-get install gh
52+
fi
53+
- name: Checkout Repository
54+
uses: actions/checkout@v4
55+
with:
56+
show-progress: true
57+
fetch-depth: 0 # Full depth for accurate tags
58+
ref: ${{ github.event.inputs.version }}
5059
- name: Reset release state
5160
shell: bash
5261
run: |
62+
current_branch=$(git branch --show-current)
63+
VERSION=$(cat VERSION)
64+
echo "VERSION=$VERSION" >> $GITHUB_ENV
65+
echo "Generating a release:"
66+
echo " Workflow dispatch inputs:
67+
echo " Input branch : ${{ github.event.inputs.branch }}"
68+
echo " Input version : ${{ github.event.inputs.version }}"
69+
echo " VERSION file parsed from branch:"
70+
echo " Current branch (from checkout): $current_branch"
71+
echo " XDK Version: $VERSION"
72+
echo ""
5373
echo "TODO: Here we should reset the release state, delete existing draft releases etc, if necessary."
5474
- name: Read VERSION File
5575
id: read_version
5676
shell: bash
5777
run: |
5878
echo "Checking ref_name: ${{ github.ref_name }}"
59-
VERSION=$(cat VERSION)
60-
echo "VERSION=$VERSION" >> $GITHUB_ENV
6179
if [[ "$VERSION" == *"SNAPSHOT"* ]]; then
62-
echo "This is a SNAPSHOT version. Skipping release."
80+
current_release=${VERSION%-SNAPSHOT}
81+
echo "This is a SNAPSHOT version. Release version will be: $current_release"
6382
exit 0
6483
else
65-
echo "This is a release version. Proceeding with release."
84+
echo "This is a release version. If the release exists already, it may not be overwritten for some situations."
6685
current_release="$VERSION"
6786
echo "CURRENT_RELEASE=v$VERSION" >> $GITHUB_ENV
6887
fi
6988
last_release=$(gh release view --json tagName -q '.tagName')
7089
echo "LAST_RELEASE=$last_release" >> $GITHUB_ENV
7190
if [ "$current_release" == "$last_release" ]; then
91+
#
92+
# TODO: This may actually be replaced by a Gradle check, like xdk:checkUnreleased
93+
# We want to write as little build logic as possible in bash scripts and GitHub
94+
# workflows, and as much as possible in Kotlin and Gradle.
95+
#
7296
echo "This version has already been released. Skipping release."
7397
exit 1
7498
fi
99+
#
100+
# Resolve artifact suffix. On Windows it'z "zip" right now, previously we had .exe files for a self
101+
# extracting installer.
102+
# TODO: This can easily be reverted to that behavior again, later.
103+
# TODO: Ensure brew hook works again.
104+
#
75105
echo "ARTIFACT_SUFFIX=tar.gz" >> $GITHUB_ENV
76106
if [ "${{ matrix.os }}" == "windows-latest" ]; then
77107
echo "This is a Windows build."
@@ -100,31 +130,49 @@ jobs:
100130
shell: bash
101131
run: |
102132
# TODO: Just use github.ref like a normal person
103-
if git tag --contains ${{ github.sha }} | grep -q ${{ env.VERSION }}"; then
133+
echo "RELEASE_TAG=release/v${{ env.VERSION }}" >> $GITHUB_ENV
134+
echo "Added release tag to environment: $RELEASE_TAG"
135+
if git tag --contains ${{ github.sha }} | grep -q ${{ env.RELEASE_TAG }}"; then
104136
echo "Tag release version tag already exists for the latest commit."
105137
echo "TAG_EXISTS=true" >> $GITHUB_ENV
106138
else
107-
echo "Tag release version tag already exists for the latest commit."
139+
echo "Tag release version tag does not exist for the last commit."
108140
echo "TAG_EXISTS=false" >> $GITHUB_ENV
109-
exit 1 # Should have been created in build with -PsnapshotOnly = false
141+
# exit 1 # Should have been created in build with -PsnapshotOnly = false
110142
fi
111-
- name: Upload artifacts
112-
uses: actions/upload-artifact@v4
113-
with:
114-
name: xdk-${{ env.VERSION }}-${{ env.OS_NAME }}.${{ env.ARTIFACT_SUFFIX }}
115-
path: xdk/build/distributions/xdk*${{ env.OS_NAME }}*.${{ env.ARTIFACT_SUFFIX }}
116-
- name: Install GitHub CLI (if necessary)
143+
# If this is run after the publish artifacts, and we do allow writing release artifacts from the push flow, these
144+
# may be included in the release too, and the tag should exist.
145+
- name: Check if release already exists
146+
id: check_release
147+
shell: bash
117148
run: |
118-
if ! command -v gh &> /dev/null; then
119-
echo "Installing GitHub CLI..."
120-
sudo apt-get update
121-
sudo apt-get install gh
149+
if gh release view ${{ env.VERSION }}; then
150+
echo "Release already exists."
151+
echo "CURRENT_RELEASE=$VERSION" >> $GITHUB_ENV
152+
else
153+
echo "Release does not exist."
154+
echo "CURRENT_RELEASE=" >> $GITHUB_ENV
122155
fi
156+
- name: Create GitHub release skeleton
157+
if: env.CURRENT_RELEASE != ''
158+
shell: bash
159+
run: |
160+
echo "Attempting to create release skeleton for tag ${{ env.RELEASE_TAG }} and "
161+
gh release create ${{ env.VERSION }} --title "XDK ${{ env.VERSION }}" --draft --target
162+
#- name: Upload release assets
163+
#uses: actions/upload-artifact@v4
164+
#uses: actions/upload-artifact@v4
165+
#with:
166+
# name: xdk-${{ env.VERSION }}-${{ env.OS_NAME }}.${{ env.ARTIFACT_SUFFIX }}
167+
# path: xdk/build/distributions/xdk*${{ env.OS_NAME }}*.${{ env.ARTIFACT_SUFFIX }}
123168

169+
# TODO: Disabled for now, but is meant to consume the release artifacts created in the previous job, for all our
170+
# platforms.
124171
create-release:
125172
name: Create Release
126173
runs-on: ubuntu-latest
127174
needs: build-release-artifacts # This job will wait for all builds to complete
175+
if: ${{ false }}
128176
steps:
129177
- name: Checkout Repository
130178
uses: actions/checkout@v4
@@ -148,3 +196,51 @@ jobs:
148196
run: |
149197
gh release upload ${{ env.VERSION }} \
150198
./artifacts/xdk-${{ env.VERSION }}-*.${{ env.ARTIFACT_SUFFIX }}
199+
200+
#
201+
# USAGE
202+
# gh release create [<tag>] [<files>...]
203+
#
204+
# ALIASES
205+
# gh release new
206+
#
207+
# FLAGS
208+
# --discussion-category string Start a discussion in the specified category
209+
# -d, --draft Save the release as a draft instead of publishing it
210+
# --generate-notes Automatically generate title and notes for the release
211+
# --latest Mark this release as "Latest" (default [automatic based on date and version]). --latest=false to explicitly NOT set as latest
212+
# -n, --notes string Release notes
213+
# -F, --notes-file file Read release notes from file (use "-" to read from standard input)
214+
# --notes-from-tag Automatically generate notes from annotated tag
215+
# --notes-start-tag string Tag to use as the starting point for generating release notes
216+
# -p, --prerelease Mark the release as a prerelease
217+
# --target branch Target branch or full commit SHA (default [main branch])
218+
# -t, --title string Release title
219+
# --verify-tag Abort in case the git tag doesn't already exist in the remote repository
220+
#
221+
# INHERITED FLAGS
222+
# --help Show help for command
223+
# -R, --repo [HOST/]OWNER/REPO Select another repository using the [HOST/]OWNER/REPO format
224+
#
225+
# EXAMPLES
226+
# Interactively create a release
227+
# gh release create
228+
# Interactively create a release from specific tag
229+
# gh release create v1.2.3
230+
# Non-interactively create a release
231+
# gh release create v1.2.3 --notes "bugfix release"
232+
# Use automatically generated release notes
233+
# gh release create v1.2.3 --generate-notes
234+
# Use release notes from a file
235+
# gh release create v1.2.3 -F release-notes.md
236+
# Use annotated tag notes
237+
# gh release create v1.2.3 --notes-from-tag
238+
# Don't mark the release as latest
239+
# gh release create v1.2.3 --latest=false
240+
# Upload all tarballs in a directory as release assets
241+
# gh release create v1.2.3 ./dist/*.tgz
242+
# Upload a release asset with a display label
243+
# gh release create v1.2.3 '/path/to/asset.zip#My display label'
244+
# Create a release and start a discussion
245+
# gh release create v1.2.3 --discussion-category "General"
246+
#

build-logic/common-plugins/src/main/kotlin/GitHubProtocol.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ data class GitHubProtocol(private val project: Project) {
3232
}
3333

3434
private val semanticVersion = project.property("semanticVersion") as SemanticVersion
35-
private val releaseVersion = project.releaseVersion()
3635
private val artifactBaseVersion = semanticVersion.artifactVersion.removeSuffix("-SNAPSHOT")
3736
private val tagPrefix = if (semanticVersion.isSnapshot()) "snapshot/" else "release/"
3837
private val localTag = "${tagPrefix}v$artifactBaseVersion"
@@ -171,7 +170,8 @@ data class GitHubProtocol(private val project: Project) {
171170
fun isReleased(): Boolean = project.run {
172171
// gh release view <version> return if release already exists.
173172
//currentVersion = senamticVersion.ar
174-
var currentVersion = semanticVersion.artifactVersion
173+
// TODO: We could also do it with "gh release view --json tagName -q '.tagName'"
174+
val currentVersion = semanticVersion.artifactVersion
175175
val releaseVersion = project.releaseVersion()
176176
val desc = if (releaseVersion != currentVersion) "'$releaseVersion'" else "the same."
177177
logger.lifecycle("$prefix Current project version is '$currentVersion', release version would be $desc")

xdk/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ val ensureTags by tasks.registering {
224224
// so that we confirm that the XDK artifact is equally legal, even if we don't look 100% like a Java artifact
225225
// For mavenCentral this may still involve faking a jar file, or shipping XDK as a jar file with all other
226226
// stuff as reasources. It should not be a big problem and can be wrapped in abstraction.
227-
val relaseXvm by tasks.registering {
227+
val releaseXvm by tasks.registering {
228228
description = "Trigger a GitHub workflow that builds and releases the current branch at the last commit."
229229
doLast {
230230
xdkBuildLogic.gitHubProtocol().triggerRelease()

0 commit comments

Comments
 (0)