Skip to content

Commit cd2e80a

Browse files
authored
chore: improve release tagging to support pre-releases (#3612)
This updates the 'npm publish' and 'github release' steps of the release process to do the right thing for pre-releases. If a release for a pre-release tag (one with hyphen) is started, this will now properly avoid tagging the npm package and github release as latest.
1 parent 8f13a9e commit cd2e80a

File tree

4 files changed

+44
-8
lines changed

4 files changed

+44
-8
lines changed

.ci/Makefile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,7 @@ create-arn-file: validate-release-notes-url
9797
@RELEASE_NOTES_URL=$(RELEASE_NOTES_URL) ./scripts/create-arn-table.sh
9898

9999
github-release: validate-ref-name
100-
@gh release list
101-
@gh release create $(GITHUB_REF_NAME) \
102-
--latest \
103-
--title '$(GITHUB_REF_NAME)' \
104-
--notes-file $(AWS_FOLDER)/$(SUFFIX_ARN_FILE)
100+
echo ../dev-utils/github-release.sh "$(GITHUB_REF_NAME)" "$(AWS_FOLDER)/$(SUFFIX_ARN_FILE)"
105101

106102
validate-version:
107103
ifndef AGENT_VERSION

.github/workflows/release.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ jobs:
6969
- name: npm publish
7070
run: |-
7171
echo "//registry.npmjs.org/:_authToken=${{ env.NPMJS_TOKEN }}" > .npmrc
72-
npm publish --tag=latest --otp=${{ env.TOTP_CODE }}
72+
# Publishing without a '--tag=...' will do the right thing: "latest"
73+
# if this is a non-pre-release, no tag if this is a pre-release.
74+
npm publish --otp=${{ env.TOTP_CODE }}
7375
7476
- if: always()
7577
uses: elastic/apm-pipeline-library/.github/actions/notify-build-status@current

CONTRIBUTING.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ A release involves the following published artifacts:
218218
If this is a new major release, then:
219219
220220
- [Create an issue](https://github.com/elastic/website-requests/issues/new) to request an update of the [EOL table](https://www.elastic.co/support/eol).
221-
- Update the "Active release branches" section of the main README.
221+
- Update the "Active release branches" section of the main "README.md".
222222
- Update the "release.yml" for the new "N.x" *maintenance* branch as follows:
223223
- The `npm publish ...` call must include a `--tag=latest-<major>` option.
224-
- The `gh release create ...` call must include a `--latest=false` option.

dev-utils/github-release.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bash
2+
3+
# Create a GitHub release. If the given tag name is the *latest* version, and
4+
# is not a pre-release, then the GH release will be marked as the latest.
5+
# (This is typically only run from the release.yml CI workflow.)
6+
#
7+
# Usage:
8+
# ./dev-utils/github-release.sh TAG_NAME RELEASE_NOTES_FILE
9+
# Example:
10+
# ./dev-utils/github-release.sh v3.49.1 ../build/aws/arn-file.md
11+
#
12+
# - For auth, this expects the 'GH_TOKEN' envvar to have been set.
13+
# - The 'TAG_NAME' is typically from the 'GITHUB_REF_NAME' variable
14+
# (https://docs.github.com/en/actions/learn-github-actions/variables)
15+
# from a GitHub Actions workflow run.
16+
# - The 'RELEASE_NOTES_FILE' is a path to an already built file to use as
17+
# the release notes (using GitHub-flavored Markdown).
18+
19+
set -euo pipefail
20+
21+
readonly TAG_NAME="$1"
22+
readonly RELEASE_NOTES_FILE="$2"
23+
24+
echo "INFO: List current GitHub releases"
25+
gh release list
26+
27+
# The latest (by semver version ordering) git version tag, excluding pre-releases.
28+
readonly LATEST_GIT_TAG=$(git tag --list --sort=version:refname "v*" | grep -v - | tail -n1)
29+
if [[ "$TAG_NAME" == "$LATEST_GIT_TAG" ]]; then
30+
IS_LATEST=true
31+
else
32+
IS_LATEST=false
33+
fi
34+
35+
echo "INFO: Create '$TAG_NAME' GitHub release (latest=$IS_LATEST)."
36+
gh release create "$TAG_NAME" \
37+
--title "$TAG_NAME" \
38+
--notes-file "$RELEASE_NOTES_FILE" \
39+
--latest=$IS_LATEST

0 commit comments

Comments
 (0)