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

feat: automatic versioning when release published [gh-516] #769

Merged
merged 23 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6018a34
feat: automatic versioning when release published [gh-516]
Jun 22, 2023
5aa4d08
Merge branch 'main' into nahuelon/gh-516/automatic-release-versioning
Jun 23, 2023
c27a08b
chore: adjust permissions to push back version and changelog changes …
Jun 23, 2023
8f1e3e0
Merge branch 'main' into nahuelon/gh-516/automatic-release-versioning
Jun 23, 2023
befd4dd
fix: npm ci for the complete monorepo [gh-516]
Jun 23, 2023
7680b92
Merge branch 'main' into nahuelon/gh-516/automatic-release-versioning
Jun 23, 2023
a86ae9a
fix: add prerelease a final version [gh-516]
Jun 26, 2023
4a8f32f
chore: set version 0.0.1 in package.json [gh-516]
Jun 26, 2023
fd81cf9
chore: set monorepo 0.0.1 verion [gh-516]
Jun 26, 2023
af578fd
Merge branch 'main' into nahuelon/gh-516/automatic-release-versioning
Jun 26, 2023
f3748b8
Merge branch 'main' into nahuelon/gh-516/automatic-release-versioning
Jun 26, 2023
da618c5
chore: remove content write permission [gh-516]
Jun 26, 2023
b266be6
chore: get latest version from NPM [gh-516]
Jun 28, 2023
6c42756
chore: do not fetch version from npm registry [gh-761]
Jun 29, 2023
8c57d73
test: increase timeout [gh-761]
Jun 29, 2023
5c1553b
test: add console.error for debuggin [gh-516]
Jun 29, 2023
bde7395
test: add console.info for debugging [gh-516]
Jun 29, 2023
710fdb5
test: fix resource request limit [gh-516]
Jun 29, 2023
d5296b3
Merge branch 'main' into nahuelon/gh-516/automatic-release-versioning
Jun 29, 2023
cdf2875
chore: disable oclif version warking adding '-dev' version suffix [gh…
Jun 30, 2023
f1a450d
chore: update readme/contributing release docs [gh-516]
Jun 30, 2023
abfb536
chore: update readme/contributing release docs [gh-516]
Jun 30, 2023
a7caf10
Merge branch 'main' into nahuelon/gh-516/automatic-release-versioning
Jun 30, 2023
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
20 changes: 20 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
changelog:
exclude:
labels:
- ignore-for-release
categories:
- title: New Features
labels:
- enhancement
- title: Bug Fixes
labels:
- bug
- title: Other Changes
labels:
- '*'
exclude:
labels:
- dependencies
- title: Improvements
labels:
- "dependencies"
78 changes: 73 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name: Publish Package to npmjs
on:
release:
types: [created]
types: [published]
jobs:
build:
# Build package and publish a prerelease
prerelease:
permissions:
id-token: write
runs-on: ubuntu-latest
Expand All @@ -14,12 +15,79 @@ jobs:
with:
node-version: '16.x'
registry-url: 'https://registry.npmjs.org'
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# Ensure that the README is published with the package
- run: rm -f packages/cli/README.md && cp README.md packages/cli
- run: npm ci
- run: npm publish --provenance --workspace packages/cli
- name: Set version and publish prerelease for 'cli' package
run: |
npm --no-git-tag-version version ${{ github.event.release.tag_name }}-prerelease --workspace packages/cli
npm publish --provenance --workspace packages/cli --tag prerelease
- name: Set version and publish prerelease for 'create-cli' package
run: |
npm --no-git-tag-version version ${{ github.event.release.tag_name }}-prerelease --workspace packages/create-cli
npm publish --provenance --workspace packages/create-cli --tag prerelease
- name: Output prerelease packages versions
run: |
npm pkg get version --workspace packages/cli
npm pkg get version --workspace packages/create-cli
# Slack failure alert
- name: Slack Failure Notification
if: ${{ failure() }}
uses: rtCamp/action-slack-notify@v2
env:
SLACK_USERNAME: Checkly Github Bot
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_CHANNEL: cli
SLACK_ICON: https://github.com/checkly.png?size=48
SLACK_COLOR: ${{ job.status }}
SLACK_TITLE: ':red_circle: NPM prerelease failed'
SLACK_MESSAGE: by ${{ github.actor }}
SLACK_FOOTER: ''
# Slack success alert
- name: Slack Success Notification
if: ${{ success() }}
uses: rtCamp/action-slack-notify@v2
env:
SLACK_USERNAME: Checkly Github Bot
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_CHANNEL: cli
SLACK_ICON: https://github.com/checkly.png?size=48
SLACK_COLOR: ${{ job.status }}
SLACK_TITLE: ':white_check_mark: NPM prerelease succeeded'
SLACK_MESSAGE: by ${{ github.actor }}
SLACK_FOOTER: ''
# Publish package to NPM
release:
runs-on: ubuntu-latest
environment: production
needs: prerelease
steps:
- uses: actions/checkout@v3
with:
ref: main
- uses: actions/setup-node@v3
with:
node-version: '16.x'
registry-url: 'https://registry.npmjs.org'
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# Ensure that the README is published with the package
- run: rm -f packages/cli/README.md && cp README.md packages/cli
- run: npm ci
- name: Set version and publish 'cli' package
run: |
npm --no-git-tag-version version ${{ github.event.release.tag_name }} --workspace packages/cli
npm publish --provenance --workspace packages/cli
- name: Set version and publish 'create-cli' package
run: |
npm --no-git-tag-version version ${{ github.event.release.tag_name }} --workspace packages/create-cli
npm publish --provenance --workspace packages/create-cli
- name: Output final packages versions
run: |
npm pkg get version --workspace packages/cli
npm pkg get version --workspace packages/create-cli
# Slack failure alert
- name: Slack Failure Notification
if: ${{ failure() }}
Expand All @@ -30,7 +98,7 @@ jobs:
SLACK_CHANNEL: cli
SLACK_ICON: https://github.com/checkly.png?size=48
SLACK_COLOR: ${{ job.status }}
SLACK_TITLE: ':red_circle: NPM release failed'
SLACK_TITLE: ':red_circle: NPM publish failed'
SLACK_MESSAGE: by ${{ github.actor }}
SLACK_FOOTER: ''
# Slack success alert
Expand All @@ -43,6 +111,6 @@ jobs:
SLACK_CHANNEL: cli
SLACK_ICON: https://github.com/checkly.png?size=48
SLACK_COLOR: ${{ job.status }}
SLACK_TITLE: ':white_check_mark: NPM release succeeded'
SLACK_TITLE: ':white_check_mark: NPM publish succeeded'
SLACK_MESSAGE: by ${{ github.actor }}
SLACK_FOOTER: ''
22 changes: 8 additions & 14 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ When running commands from the `packages/create-cli` directory, the `--workspace

## Running locally

Use `CHECKLY_CLI_VERSION` environment variable to set the latest version you want to test.

You can configure the stage (`production`, `staging`, `development` or `local`) using `CHECKLY_ENV` environment variable. Use `CHECKLY_ENV=local` if you want to point the API URL to your local backend `http://localhost:3000`.

Also, you can use the `watch` mode to compile during your coding. You can use the following command to start your local environment:
Expand Down Expand Up @@ -66,23 +68,15 @@ npm install [email protected].<PR-NUMBER>.<COMMIT_SHORT_SHA>

## Releasing

### Releasing `checkly` (CLI)

To release the project to NPM:

1. Update the `version` field in the [CLI package.json](./packages/cli/package.json)
2. Create a new release in GitHub [here](https://github.com/checkly/checkly-cli/releases/new)

The new version will then automatically be released by the corresponding GitHub action [here](https://github.com/checkly/checkly-cli/actions/workflows/release.yml).
### Releasing `checkly` packages

### Releasing `create-checkly`
To release the [create-checkly](https://www.npmjs.com/package/create-checkly) package:
Both packages [checkly](https://www.npmjs.com/package/checkly) and [create-cli](https://www.npmjs.com/package/create-checkly) are built and published by the corresponding GitHub action [here](https://github.com/checkly/checkly-cli/actions/workflows/release.yml).

1. Update the `version` field in the [create-cli package.json](./packages/create-cli/package.json)
2. Trigger the [GitHub action](https://github.com/checkly/checkly-cli/actions/workflows/release-create-package.yml)
* Only release from `main`
To release packages to NPM:

The new version will then be built and published to NPM.
1. Publish a Github Release with a valid tag `v#.#.#` and click the `Generate release notes` button to auto-generate notes following format defined [here](https://github.com/checkly/checkly-cli/blob/main/.github/release.yml)
2. When release is published the Github action is triggered. It builds and publishes `v#.#.#-prerelease` prereleases (for both packages).
3. A `production` deployment will be waiting for approval. After it's approved, the `v#.#.#` version will be published and set as `latest`

## Style Guide

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ Official docs are over at [checklyhq.com/docs/cli](https://checklyhq.com/docs/cl

# Local Development

Use `CHECKLY_CLI_VERSION` environment variable to set the latest version you want to test.

To get started with local development check [CONTRIBUTING.MD](https://github.com/checkly/checkly-cli/blob/main/CONTRIBUTING.md)
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@checkly/cli-monorepo",
"private": true,
"version": "0.0.0",
"version": "0.0.1",
"scripts": {
"lint": "eslint . --ext .ts,.js,.mjs",
"lint:fix": "eslint . --ext .ts,.js,.mjs --fix",
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "checkly",
"version": "4.0.9",
"version": "0.0.1-dev",
"description": "Checkly CLI",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -18,7 +18,6 @@
"test": "jest --selectProjects unit",
"test:e2e": "npm run prepare && cross-env NODE_CONFIG_DIR=./e2e/config jest --selectProjects E2E",
"test:e2e:local": "cross-env CHECKLY_ENV=local npm run test:e2e",
"version": "node -e \"console.log(require('./package.json').version)\"",
"watch": "tsc --watch"
},
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions packages/create-cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/create-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-checkly",
"version": "0.0.4",
"version": "0.0.1-dev",
"description": "Checkly Create CLI",
"type": "module",
"main": "dist/index.js",
Expand Down
4 changes: 2 additions & 2 deletions packages/create-cli/src/commands/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Command, Flags } from '@oclif/core'
import prompts from 'prompts'
import {
getUserGreeting,
getVersion,
header,
bail,
footer,
Expand Down Expand Up @@ -47,7 +46,8 @@ export default class Bootstrap extends Command {
prompts.override({ template })
}

const [version, greeting] = await Promise.all([getVersion(), getUserGreeting()])
const version = process.env.CHECKLY_CLI_VERSION ?? this.config.version
const greeting = await getUserGreeting()

await header(version, greeting)

Expand Down
5 changes: 0 additions & 5 deletions packages/create-cli/src/utils/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ function sleep (ms: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, ms))
}

export async function getVersion (): Promise<string> {
const { data } = await axios.get('https://registry.npmjs.org/checkly/latest')
return data.version
}

export async function getUserGreeting (): Promise<string> {
const name = await fullName()
return name ? `Hi ${name}!` : 'Hi there!'
Expand Down
Loading