forked from open-telemetry/opentelemetry-js-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add automated release workflows (open-telemetry#366)
* chore: update typescript to 4.x and gts to 3.x (open-telemetry#336) Update typescript and gts to new major versions. Additionally update eslint and plugins to latest versions and fix some other minor issues like repository field in package.json. * ci: added auto-publish release workflows and updated docs * use express instr for example Co-authored-by: Gerhard Stöbich <deb2001-github@yahoo.de> Co-authored-by: Valentin Marchaud <thisismac47@gmail.com> Co-authored-by: Daniel Dyla <dyladan@users.noreply.github.com>
- Loading branch information
1 parent
92656a3
commit f106054
Showing
8 changed files
with
194 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
name: Publish a New Release | ||
on: | ||
pull_request: | ||
branches: [main] | ||
types: [closed] | ||
|
||
jobs: | ||
publish_to_npm: | ||
name: Publish to NPM and GitHub | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
# Determine if PR was a valid merged release PR. If so, publish the new release. Otherwise, do nothing. | ||
# This is a valid release PR if the following 3 things are true: | ||
# 1. The head (source) branch of the PR matches the expected "release/x.y.z" pattern | ||
# 2. The PR has been merged, rather than closed | ||
# 3. The head (source) repo of the PR is not a fork, or in other words the PR is made from a branch within the main repo | ||
- name: Validate Release PR | ||
id: validate_pr | ||
run: | | ||
merged=${{ github.event.pull_request.merged }} | ||
forked=${{ github.event.pull_request.head.repo.fork }} | ||
echo "Source branch is ${{ github.head_ref }}; merged = $merged; from a fork = $forked" | ||
if [ $(grep -E '^release/[0-9]+\.[0-9]+\..+$' <<< '${{ github.head_ref }}') ] && [ $merged = true ] && [ $forked = false ] | ||
then | ||
echo "::set-output name=is_release::true" | ||
fi | ||
# Get release version and draft release tag from PR metadata | ||
- name: Get Release Metadata | ||
if: steps.validate_pr.outputs.is_release | ||
id: metadata | ||
run: | | ||
version=$(cut -d'/' -f2 <<< '${{ github.head_ref }}') | ||
echo "::set-output name=version::$version" | ||
- name: Checkout Repository | ||
if: steps.validate_pr.outputs.is_release | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Setup Node | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: '14.x' | ||
registry-url: 'https://registry.npmjs.org' | ||
|
||
- name: Publish to NPM | ||
if: steps.validate_pr.outputs.is_release | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
run: ./scripts/publish.sh | ||
|
||
# Generates changelog without the "Unreleased" portion for use in release body | ||
# Newlines must be URL-encoded to render properly in the GitHub UI | ||
- name: Generate Release Body | ||
if: steps.validate_pr.outputs.is_release | ||
id: generate-changelog | ||
env: | ||
GITHUB_AUTH: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
description=$(npx lerna-changelog | sed '1,3d') | ||
description="${description//'%'/'%25'}" | ||
description="${description//$'\n'/'%0A'}" | ||
description="${description//$'\r'/'%0D'}" | ||
echo "::set-output name=CHANGELOG::$description" | ||
- name: Create GitHub Release | ||
if: steps.validate_pr.outputs.is_release | ||
id: make-release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: 'v${{ steps.metadata.outputs.version }}' | ||
commitish: main | ||
release_name: 'v${{ steps.metadata.outputs.version }} Release' | ||
body: "${{ steps.generate-changelog.outputs.CHANGELOG }}" | ||
draft: false | ||
prerelease: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
name: Create New Release PR | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
version: | ||
description: The semver-compliant version to tag the release with, e.g. 1.2.3, 1.0.0-rc.1 | ||
required: true | ||
|
||
jobs: | ||
create_release_pr: | ||
name: Create Release PR and Draft Release | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Setup Node | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: '14.x' | ||
|
||
- name: Cache Dependencies | ||
uses: actions/cache@v2 | ||
with: | ||
path: | | ||
node_modules | ||
package-lock.json | ||
detectors/node/*/node_modules | ||
metapackages/*/node_modules | ||
packages/*/node_modules | ||
plugins/node/*/node_modules | ||
plugins/web/*/node_modules | ||
propagators/*/node_modules | ||
key: ${{ runner.os }}-${{ matrix.container }}-${{ hashFiles('**/package.json') }} | ||
|
||
# Bump versions in all package.json and version.ts files | ||
- name: Prepare Release | ||
run: | | ||
npm install | ||
npm --no-git-tag-version version ${{ github.event.inputs.version }} | ||
npx lerna publish ${{ github.event.inputs.version }} --skip-npm --no-git-tag-version --no-push --yes | ||
npx lerna bootstrap --no-ci | ||
- name: Update Changelog | ||
env: | ||
GITHUB_AUTH: ${{ secrets.GITHUB_TOKEN }} | ||
run: ./scripts/changelog-update.sh ${{ github.event.inputs.version }} | ||
|
||
# Make PR with version bumps and changelog update. Merging this PR triggers publish workflow. | ||
# See: https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/.github/workflows/publish.yml | ||
- name: Create Release PR | ||
uses: peter-evans/create-pull-request@v3 | ||
with: | ||
branch: release/${{ github.event.inputs.version }} | ||
commit-message: 'chore: ${{ github.event.inputs.version }} release proposal' | ||
title: 'chore: ${{ github.event.inputs.version }} release proposal' | ||
body: | | ||
This is an auto-generated release PR. If additional changes need to be incorporated before the release, the CHANGELOG must be updated manually. | ||
Merging this PR will automatically release all packages to NPM. | ||
delete-branch: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
echo " | ||
## $1 | ||
" > delete_me.txt | ||
npx lerna-changelog | sed '1,3d' >> delete_me.txt | ||
sed -i -e '/## Unreleased/r delete_me.txt' CHANGELOG.md | ||
rm delete_me.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
|
||
for path in $(cat lerna.json | jq '.packages[]'); do | ||
base=$(sed 's/"//g' <<< $path) # Remove quotes | ||
for package in $base; do | ||
if [ -d $package ]; then | ||
echo Publishing to NPM: $package | ||
pushd $package | ||
npm publish | ||
popd | ||
fi | ||
done | ||
done |