Skip to content

Commit a0794d3

Browse files
dmihalcik-virtruel-virt
authored andcommitted
chore(ci): Fixes for version checks upon release (#671)
- The version information must be up to date and accurate before tagging and publishing releases (cherry picked from commit 0e97899)
1 parent 29645f2 commit a0794d3

File tree

2 files changed

+153
-5
lines changed

2 files changed

+153
-5
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
name: "Reusable worflow: Deliver Client to npm registry"
2+
3+
on:
4+
workflow_call:
5+
secrets:
6+
NPM_TOKEN:
7+
required: true
8+
9+
# Default empty permissions for all jobs
10+
permissions: {}
11+
12+
jobs:
13+
deliver-ghp:
14+
permissions:
15+
contents: write
16+
packages: write
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: "Checkout repo"
21+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
22+
with:
23+
persist-credentials: false
24+
25+
- name: "Setup node"
26+
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
27+
with:
28+
node-version: "22"
29+
registry-url: https://npm.pkg.github.com
30+
31+
- name: "Check version number is same between tag, library, and/or release"
32+
id: check-version
33+
run: |
34+
scripts/check-version-is.sh "${GITHUB_REF}"
35+
36+
- name: "Output build metadata"
37+
id: guess-build-metadata
38+
run: |
39+
FULL_VERSION=$(.github/workflows/gh-semver.sh)
40+
DIST_TAG=$(.github/workflows/guess-dist-tag.sh)
41+
42+
echo "FULL_VERSION=$FULL_VERSION" >> "$GITHUB_OUTPUT"
43+
echo "DIST_TAG=$DIST_TAG" >> "$GITHUB_OUTPUT"
44+
45+
- name: "Run: make doc"
46+
run: |
47+
make doc
48+
49+
- name: "Echo info"
50+
env:
51+
DIST_TAG: ${{ steps.guess-build-metadata.outputs.DIST_TAG }}
52+
FULL_VERSION: ${{ steps.guess-build-metadata.outputs.FULL_VERSION }}
53+
run: |
54+
echo "::notice file=lib/package.json::Will be published to \
55+
[GitHub Packages](https://github.com/opentdf/web-sdk/pkgs/npm/client) \
56+
as $DIST_TAG \
57+
with version=[$FULL_VERSION]"
58+
59+
- name: "Deliver to GitHub Packages"
60+
env:
61+
DIST_TAG: ${{ steps.guess-build-metadata.outputs.DIST_TAG }}
62+
FULL_VERSION: ${{ steps.guess-build-metadata.outputs.FULL_VERSION }}
63+
NODE_AUTH_TOKEN: ${{ github.token }}
64+
run: |
65+
bash scripts/deliver-to-npm-registry.sh "$FULL_VERSION" "$DIST_TAG"
66+
67+
- name: "Echo info to Run Summary"
68+
run: |
69+
{
70+
echo "- [Client Library](https://github.com/opentdf/web-sdk/pkgs/npm/client)"
71+
echo "- [Command Line Tool](https://github.com/opentdf/web-sdk/pkgs/npm/cli)"
72+
} >>"$GITHUB_STEP_SUMMARY"
73+
74+
- name: "Publish documentation to gh-pages"
75+
uses: JamesIves/github-pages-deploy-action@6c2d9db40f9296374acc17b90404b6e8864128c8 # v4.7.3
76+
with:
77+
branch: gh-pages
78+
folder: lib/dist/docs
79+
80+
deliver-npmjs:
81+
permissions:
82+
contents: read
83+
runs-on: ubuntu-latest
84+
steps:
85+
- name: "Checkout repo"
86+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
87+
with:
88+
persist-credentials: false
89+
90+
- name: "Setup node"
91+
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
92+
with:
93+
node-version: "22"
94+
registry-url: "https://registry.npmjs.org"
95+
96+
- name: "Run: make all"
97+
run: |
98+
make all
99+
100+
- name: "Output build metadata"
101+
id: guess-build-metadata
102+
run: |
103+
FULL_VERSION=$(.github/workflows/gh-semver.sh)
104+
DIST_TAG=$(.github/workflows/guess-dist-tag.sh)
105+
106+
echo "FULL_VERSION=$FULL_VERSION" >> "$GITHUB_OUTPUT"
107+
echo "DIST_TAG=$DIST_TAG" >> "$GITHUB_OUTPUT"
108+
109+
- name: "Deliver to npmjs"
110+
env:
111+
DIST_TAG: ${{ steps.guess-build-metadata.outputs.DIST_TAG }}
112+
FULL_VERSION: ${{ steps.guess-build-metadata.outputs.FULL_VERSION }}
113+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
114+
run: |
115+
bash scripts/deliver-to-npm-registry.sh "$FULL_VERSION" "$DIST_TAG"
116+
117+
- name: "Echo info to Run Summary"
118+
env:
119+
FULL_VERSION: ${{ steps.guess-build-metadata.outputs.FULL_VERSION }}
120+
run: |
121+
{
122+
echo "- [Client Library](https://www.npmjs.com/package/@opentdf/sdk/v/$FULL_VERSION)"
123+
echo "- [Command Line Tool](https://www.npmjs.com/package/@opentdf/ctl/v/$FULL_VERSION)"
124+
echo "- [unpkg](https://unpkg.com/browse/@opentdf/sdk@$FULL_VERSION)"
125+
} >>"$GITHUB_STEP_SUMMARY"

scripts/check-version-is.sh

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,38 @@
11
#!/usr/bin/env bash
22
# Validate that version number is same across all expected files
3+
# If no parameter is found, validates that the lib/package.json is consistent throughout the repo.
4+
#
5+
# Expected usage:
6+
# ./scripts/check-version-is.sh [expected_version, e.g. from branch or tag name]
7+
# Output:
8+
# ::error file=Makefile,line=5::Incorrect version line, should be setting it to [1.0.0]
39

410
set -euo pipefail
511

6-
lib_version="$(cd lib && node -p "require('./package.json').version")"
7-
8-
expected_version="${1:-$lib_version}"
12+
# Parse github.ref context parameter if provided
13+
if [[ ${1:-} =~ refs/heads/release/sdk/v(.*) ]]; then
14+
minor_version="${BASH_REMATCH[1]}"
15+
lib_version="$(cd lib && node -p "require('./package.json').version")"
16+
if [[ $lib_version != $minor_version* ]]; then
17+
echo "::error file=lib/package.json::lib version [$lib_version] does not start with expected minor version [$minor_version]"
18+
exit 1
19+
fi
20+
expected_version="$lib_version"
21+
elif [[ ${1:-} =~ refs/tags/sdk/v(.*) ]]; then
22+
expected_version="${BASH_REMATCH[1]}"
23+
elif [[ ${1:-} =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]]; then
24+
expected_version="${1}"
25+
else
26+
lib_version="$(cd lib && node -p "require('./package.json').version")"
27+
if [[ -n ${1:-} ]]; then
28+
echo "::error::Unrecognized ref '${1}'; ignored in favor of lib/package.json's version [${lib_version}]"
29+
fi
30+
expected_version="${lib_version}"
31+
fi
932

1033
if ! grep --fixed-strings --line-regexp --quiet "version=${expected_version}" "Makefile"; then
1134
if grep --quiet "^version=" "Makefile"; then
12-
echo "::error file=Makefile,line=$(sed -n '/version/=' Makefile)::Incorrect version line, should be setting it to [${expected_version}]"
35+
echo "::error file=Makefile,line=$(sed -n '/^version/=' Makefile)::Incorrect version line, should be setting it to [${expected_version}]"
1336
else
1437
echo "::error file=Makefile::Makefile missing version line [version=${expected_version}]"
1538
fi
@@ -18,7 +41,7 @@ fi
1841

1942
if ! grep --fixed-strings --line-regexp --quiet "export const version = '${expected_version}'; // x-release-please-version" "lib/src/version.ts"; then
2043
if grep --quiet "^export const version" "lib/src/version.ts"; then
21-
echo "::error file=lib/src/version.ts,line=$(sed -n '/export const version/=' lib/src/version.ts)::Incorrect version line, should be setting it to [${expected_version}]"
44+
echo "::error file=lib/src/version.ts,line=$(sed -n '/^export const version/=' lib/src/version.ts)::Incorrect version line, should be setting it to [${expected_version}]"
2245
else
2346
echo "::error file=lib/src/version.ts::Missing version line [version=${expected_version}]"
2447
fi

0 commit comments

Comments
 (0)