Skip to content

Commit

Permalink
support dry-run mode
Browse files Browse the repository at this point in the history
  • Loading branch information
v1v committed Apr 16, 2024
1 parent 982c923 commit 570c610
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
push:
tags:
- v*.*.*
branches:
- main
- trentm/release-process

# 'id-token' perm needed for npm publishing with provenance (see
# https://docs.npmjs.com/generating-provenance-statements#example-github-actions-workflow)
Expand All @@ -16,6 +19,8 @@ permissions:
jobs:
release:
runs-on: ubuntu-latest
env:
DRY_RUN: "${{ startsWith(github.ref, 'refs/tags') }}"
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -28,7 +33,7 @@ jobs:
- run: npm ci --ignore-scripts

- name: GitHub release
run: ./scripts/github-release.sh "packages/opentelemetry-node" "${{ env.GITHUB_REF_NAME }}"
run: ./scripts/github-release.sh "packages/opentelemetry-node" "${{ env.GITHUB_REF_NAME }}" "${{ env.DRY_RUN }}"
env:
GH_TOKEN: ${{ github.token }}

Expand All @@ -44,12 +49,16 @@ jobs:
totp/code/npmjs-elasticmachine code | TOTP_CODE
- name: npm publish
run: npm publish --otp=${{ env.TOTP_CODE }}
run: |
PUBLISH_FLAGS="--dry-run"
[ "${{ env.DRY_RUN }}" == "true" ] && PUBLISH_FLAGS="" || true
npm publish $PUBLISH_FLAGS --otp=${{ env.TOTP_CODE }}
env:
# https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages#publishing-packages-to-the-npm-registry
NODE_AUTH_TOKEN: ${{ env.NPMJS_TOKEN }}

- if: always()
# If a release tag then notify
- if: ${{ always() && startsWith(github.ref, 'refs/tags') }}
uses: elastic/apm-pipeline-library/.github/actions/notify-build-status@current
with:
vaultUrl: ${{ secrets.VAULT_ADDR }}
Expand Down
17 changes: 11 additions & 6 deletions scripts/github-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
# (This is typically only run from the release.yml CI workflow.)
#
# Usage:
# ./scripts/github-release.sh PKG_DIR TAG_NAME
# ./scripts/github-release.sh PKG_DIR TAG_NAME DRY_RUN
# Example:
# ./scripts/github-release.sh packages/opentelemetry-node v0.1.0
# ./scripts/github-release.sh packages/opentelemetry-node v0.1.0 true
#
# - For auth, this expects the 'GH_TOKEN' envvar to have been set.
# - The 'TAG_NAME' is typically from the 'GITHUB_REF_NAME' variable
Expand All @@ -27,6 +27,7 @@ function fatal {

readonly PKG_DIR="$1"
readonly TAG_NAME="$2"
readonly DRY_RUN="$3"

TOP=$(cd $(dirname $0)/../ >/dev/null; pwd)
JSON=$TOP/node_modules/.bin/json
Expand Down Expand Up @@ -66,7 +67,11 @@ fi

echo
echo "INFO: Creating '$PKG_NAME $TAG_NAME' GitHub release (latest=$IS_LATEST)"
gh release create "$TAG_NAME" \
--title "$PKG_NAME $PKG_VER" \
--notes-file build/release-notes.md \
--latest=$IS_LATEST
if [ "${DRY_RUN}" == "false" ] ; then
gh release create "$TAG_NAME" \
--title "$PKG_NAME $PKG_VER" \
--notes-file build/release-notes.md \
--latest=$IS_LATEST
else
echo "DRY-RUN: gh release create $TAG_NAME"
fi

0 comments on commit 570c610

Please sign in to comment.