Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: use semantic-release for releases #829

Merged
merged 9 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 25 additions & 19 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,24 @@ on:
is-stack-release:
type: boolean
description: Should we tag the current version as a stack release?
required: true
default: false
dry-run:
type: boolean
description: "Should we run in dry-run mode?"
required: true
default: false

permissions:
contents: write

env:
GH_TOKEN: ${{ github.token }}
contents: write # needed to push the tag and create the release

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: elastic/apm-pipeline-library/.github/actions/setup-git@current
- uses: elastic/apm-pipeline-library/.github/actions/setup-npmrc@current
with:
Expand All @@ -27,30 +32,31 @@ jobs:
vault-role-id: ${{ secrets.VAULT_ROLE_ID }}
vault-secret-id: ${{ secrets.VAULT_SECRET_ID }}
- run: npm ci # runs npm prepublish
- name: Bump the version
run: |
echo "VERSION=$(npm version)" >> $GITHUB_ENV
echo "NPM_PACKAGE=$(jq '.name' package.json) >> $GITHUB_ENV
- run: git push --tags
- uses: ./.github/actions/setup-totp
reakaleek marked this conversation as resolved.
Show resolved Hide resolved
with:
vault-url: ${{ secrets.VAULT_ADDR }}
vault-role-id: ${{ secrets.VAULT_ROLE_ID }}
vault-secret-id: ${{ secrets.VAULT_SECRET_ID }}
- name: NPM Publish
run: npm publish --otp=${TOTP_CODE}
- run: npx semantic-release --dry-run="${DRY_RUN}"
env:
DRY_RUN: ${{ github.event.inputs.dry-run }}
GITHUB_TOKEN: ${{ github.token }}

- name: Get version and package name
if: ${{ !github.event.inputs.dry-run }}
run: |
echo "VERSION=$(jq -r '.version' package.json)" >> $GITHUB_ENV
echo "NPM_PACKAGE=$(jq -r '.name' package.json) >> $GITHUB_ENV

- name: Create 'latest' dist-tag
if: ${{ !github.event.inputs.dry-run }}
run: npm dist-tag --otp=${TOTP_CODE} add "${NPM_PACKAGE}@${VERSION}" latest
v1v marked this conversation as resolved.
Show resolved Hide resolved

- name: Create 'stack_release' dist-tag
if: ${{ github.event.inputs.is-stack-release }}
if: ${{ !github.event.inputs.dry-run && github.event.inputs.is-stack-release }}
run: npm dist-tag --otp=${TOTP_CODE} add "${NPM_PACKAGE}@${VERSION}" stack_release
- name: Create Draft Release Notes
run: >-
gh release create "${VERSION}"
--title="${VERSION}"
--generate-notes
--draft
- if: always()

- if: ${{ always() && !github.event.inputs.dry-run }}
uses: elastic/apm-pipeline-library/.github/actions/notify-build-status@current
with:
vaultUrl: ${{ secrets.VAULT_ADDR }}
Expand Down
20 changes: 20 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"branches": ["main"],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
[
"@semantic-release/npm",
{
"npmPublish": false
}
],
[
"@semantic-release/exec",
{
"publishCmd": "npm publish --otp=${process.env.TOTP_CODE}"
}
],
"@semantic-release/github"
]
}
5 changes: 5 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ The release process is also automated in the way any specific commit from the ma
1. Click the green `Run workflow` button to trigger the release workflow.
1. Then you can go to the `https://www.npmjs.com/package/@elastic/synthetics` to validate that the bundles have been published.

#### Versioning
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does it pick the existing versioning if we set it to 0-0-0 in the package JSON, are we doing it based on existing tags?

Also can you post a dry-run output? I am not able to run it localy.

Copy link
Member Author

@reakaleek reakaleek Sep 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it's based on existing tags.

Will post the log output in a couple of minutes. I will also add a how to test section in the description.

Copy link
Member Author

@reakaleek reakaleek Sep 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I justed added the "How to test section". The log output can be found in the collapsible details.


The version is computed automatically with [semantic-release](https://github.com/semantic-release/semantic-release).
You must not modify the `0.0.0-development` version in the package.json file. It will be overwritten by the release process.

## CI

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