Skip to content

Commit

Permalink
🚀 Publish fix & log improvments (#88)
Browse files Browse the repository at this point in the history
- Annotate the workflow with the generated semver and tag
- Set access level to public, fixing issue with 'first publish' failing to npm (probably)
- Since npm publish depends on GHPR publish, do that first always, and share the knowledge between them
  • Loading branch information
dmihalcik-virtru authored Sep 7, 2022
1 parent e65381c commit 306cd10
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 25 deletions.
42 changes: 24 additions & 18 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -172,26 +172,41 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 5
# To publish from a release or feature branch, remove the ref == condition below
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
if: >-
(github.event_name == 'push' && github.ref == 'refs/heads/main')
|| (github.event_name == 'push' && startsWith(github.ref, 'refs/heads/release/'))
|| (github.event_name == 'release' && startsWith(github.ref, 'refs/tags/'))
outputs:
FULL_VERSION: ${{ steps.guess-build-metadata.outputs.FULL_VERSION }}
DIST_TAG: ${{ steps.guess-build-metadata.outputs.DIST_TAG }}
TARGET_VERSION: ${{ steps.check-version.outputs.TARGET_VERSION }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '16.x'
registry-url: https://npm.pkg.github.com
- run: |-
- name: Check version number is same between tag, library, and/or release
id: check-version
run: |-
if [[ ${{ github.ref }} = refs/heads/release/* ]]; then
scripts/check-version-is.sh "${GITHUB_REF##*release/}"
elif [[ ${{ github.ref }} = refs/tags/v* ]]; then
scripts/check-version-is.sh "${GITHUB_REF_NAME#v}"
else
scripts/check-version-is.sh
fi
- name: Check version number is same between tag, library, and/or release
id: guess-build-metadata
run: |-
echo "::set-output name=FULL_VERSION::$(.github/workflows/gh-semver.sh)"
echo "::set-output name=DIST_TAG::$(.github/workflows/guess-dist-tag.sh)"
- run: make test
- run: make doc
- run:
.github/workflows/publish-to.sh $(.github/workflows/gh-semver.sh)
$(.github/workflows/guess-dist-tag.sh)
- run: echo "::notice file=lib/package.json::Will be published to GitHub Packages as $(.github/workflows/guess-dist-tag.sh) with version=[$(.github/workflows/guess-dist-tag.sh)]"
- run: >-
.github/workflows/publish-to.sh ${{ steps.guess-build-metadata.outputs.FULL_VERSION }}
${{ steps.guess-build-metadata.outputs.FULL_VERSION }}
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: trigger xtest
Expand All @@ -207,28 +222,19 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 5
environment: npmjs
needs: deliver-ghp
if: >-
(github.event_name == 'push' && github.ref == 'refs/heads/main')
|| (github.event_name == 'push' && startsWith(github.ref, 'refs/heads/release/'))
|| (github.event_name == 'release' && startsWith(github.ref, 'refs/tags/'))
needs: deliver-ghp
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '16.x'
registry-url: 'https://registry.npmjs.org'
- run: |-
if [[ ${{ github.ref }} = refs/heads/release/* ]]; then
scripts/check-version-is.sh "${GITHUB_REF##*release/}"
elif [[ ${{ github.ref }} = refs/tags/v* ]]; then
scripts/check-version-is.sh "${GITHUB_REF_NAME#v}"
else
scripts/check-version-is.sh
fi
- run: make test
- run:
.github/workflows/publish-to.sh $(.github/workflows/gh-semver.sh)
$(.github/workflows/guess-dist-tag.sh)
- run: >-
.github/workflows/publish-to.sh ${{ needs.deliver-ghp.outputs.FULL_VERSION }}
${{ needs.deliver-ghp.outputs.FULL_VERSION }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
8 changes: 4 additions & 4 deletions .github/workflows/gh-semver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# git state and 'target' semver found in its package.
#
# Examples:
#
#
# Main branches build beta builds:
# ```
# package.version = 1.2.3
Expand All @@ -14,7 +14,7 @@
# ----
# 1.2.3-beta.256+bad.decaf
# ```
#
#
# Release branches build rc builds:
# ```
# package.version = 1.2.3
Expand All @@ -25,7 +25,7 @@
# ----
# 1.2.3-rc.256+bad.decaf
# ```
#
#
# Tags go to release:
# ```
# package.version = 1.2.3
Expand All @@ -36,7 +36,7 @@
# 1.2.3
# ```
#
#
#
set -euo pipefail

SCRIPTS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/publish-to.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ cd ../cli
npm --no-git-tag-version --allow-same-version version "$v" --tag "$t"
npm uninstall "@opentdf/client"
npm install "@opentdf/client@$v"
npm publish
npm publish --access public

if [[ "$GITHUB_STEP_SUMMARY" ]]; then
echo "### Published ${v}" >>$GITHUB_STEP_SUMMARY
fi
8 changes: 6 additions & 2 deletions scripts/check-version-is.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ lib_version="$(cd lib && node -p "require('./package.json').version")"
expected_version="${1:-$lib_version}"

if ! grep -Fxq "version=${expected_version}" "Makefile"; then
echo "Makefile missing version line [version=${expected_version}]"
echo "::error file=Makefile::Makefile missing version line [version=${expected_version}]"
exit 1
fi

for x in lib cli web-app; do
sub_version="$(cd $x && node -p "require('./package.json').version")"
if [[ $expected_version != "$sub_version" ]]; then
echo "${x} has incorrect version [${sub_version}], expected [${expected_version}]"
echo "::error file=${x}/package.json::Incorrect version [${sub_version}], expected [${expected_version}]"
exit 1
fi
done

if [[ "${GITHUB_ACTION}" ]]; then
echo "::set-output name=TARGET_VERSION::$expected_version"
fi

0 comments on commit 306cd10

Please sign in to comment.