Skip to content

Commit b8a7b1f

Browse files
authored
ci: use semantic-release for releases (#829)
* Use semantic-release for releases * test * test * fix * Add previous behavior of dist-tags again * Add documentation about the versioning * Fix dry-run * Fix JSON syntax * Reinstall packages to fix lockfile
1 parent 4602aa9 commit b8a7b1f

File tree

5 files changed

+9457
-11101
lines changed

5 files changed

+9457
-11101
lines changed

.github/workflows/release.yml

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,24 @@ on:
66
is-stack-release:
77
type: boolean
88
description: Should we tag the current version as a stack release?
9+
required: true
10+
default: false
11+
dry-run:
12+
type: boolean
13+
description: "Should we run in dry-run mode?"
14+
required: true
915
default: false
1016

1117
permissions:
12-
contents: write
13-
14-
env:
15-
GH_TOKEN: ${{ github.token }}
18+
contents: write # needed to push the tag and create the release
1619

1720
jobs:
1821
release:
1922
runs-on: ubuntu-latest
2023
steps:
2124
- uses: actions/checkout@v3
25+
with:
26+
fetch-depth: 0
2227
- uses: elastic/apm-pipeline-library/.github/actions/setup-git@current
2328
- uses: elastic/apm-pipeline-library/.github/actions/setup-npmrc@current
2429
with:
@@ -27,30 +32,31 @@ jobs:
2732
vault-role-id: ${{ secrets.VAULT_ROLE_ID }}
2833
vault-secret-id: ${{ secrets.VAULT_SECRET_ID }}
2934
- run: npm ci # runs npm prepublish
30-
- name: Bump the version
31-
run: |
32-
echo "VERSION=$(npm version)" >> $GITHUB_ENV
33-
echo "NPM_PACKAGE=$(jq '.name' package.json) >> $GITHUB_ENV
34-
- run: git push --tags
3535
- uses: ./.github/actions/setup-totp
3636
with:
3737
vault-url: ${{ secrets.VAULT_ADDR }}
3838
vault-role-id: ${{ secrets.VAULT_ROLE_ID }}
3939
vault-secret-id: ${{ secrets.VAULT_SECRET_ID }}
40-
- name: NPM Publish
41-
run: npm publish --otp=${TOTP_CODE}
40+
- run: npx semantic-release --dry-run="${DRY_RUN}"
41+
env:
42+
DRY_RUN: ${{ github.event.inputs.dry-run }}
43+
GITHUB_TOKEN: ${{ github.token }}
44+
45+
- name: Get version and package name
46+
if: ${{ !github.event.inputs.dry-run }}
47+
run: |
48+
echo "VERSION=$(jq -r '.version' package.json)" >> $GITHUB_ENV
49+
echo "NPM_PACKAGE=$(jq -r '.name' package.json) >> $GITHUB_ENV
50+
4251
- name: Create 'latest' dist-tag
52+
if: ${{ !github.event.inputs.dry-run }}
4353
run: npm dist-tag --otp=${TOTP_CODE} add "${NPM_PACKAGE}@${VERSION}" latest
54+
4455
- name: Create 'stack_release' dist-tag
45-
if: ${{ github.event.inputs.is-stack-release }}
56+
if: ${{ !github.event.inputs.dry-run && github.event.inputs.is-stack-release }}
4657
run: npm dist-tag --otp=${TOTP_CODE} add "${NPM_PACKAGE}@${VERSION}" stack_release
47-
- name: Create Draft Release Notes
48-
run: >-
49-
gh release create "${VERSION}"
50-
--title="${VERSION}"
51-
--generate-notes
52-
--draft
53-
- if: always()
58+
59+
- if: ${{ always() && !github.event.inputs.dry-run }}
5460
uses: elastic/apm-pipeline-library/.github/actions/notify-build-status@current
5561
with:
5662
vaultUrl: ${{ secrets.VAULT_ADDR }}

.releaserc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"branches": ["main"],
3+
"plugins": [
4+
"@semantic-release/commit-analyzer",
5+
"@semantic-release/release-notes-generator",
6+
[
7+
"@semantic-release/npm",
8+
{
9+
"npmPublish": false
10+
}
11+
],
12+
[
13+
"@semantic-release/exec",
14+
{
15+
"publishCmd": "npm publish --otp=${process.env.TOTP_CODE}"
16+
}
17+
],
18+
"@semantic-release/github"
19+
]
20+
}

CONTRIBUTING.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ The release process is also automated in the way any specific commit from the ma
151151
1. Click the green `Run workflow` button to trigger the release workflow.
152152
1. Then you can go to the `https://www.npmjs.com/package/@elastic/synthetics` to validate that the bundles have been published.
153153

154+
#### Versioning
155+
156+
The version is computed automatically with [semantic-release](https://github.com/semantic-release/semantic-release).
157+
You must not modify the `0.0.0-development` version in the package.json file. It will be overwritten by the release process.
158+
154159
## CI
155160

156161
The CI will not run builds for collaborators PRs that are not approval by a members of Elastic org,

0 commit comments

Comments
 (0)