-
Notifications
You must be signed in to change notification settings - Fork 85
[FSSDK-12881] NPM to GPR backfill + release workflow update #1168
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
Open
junaed-optimizely
wants to merge
2
commits into
master
Choose a base branch
from
junaed/fssdk-12881-ghr-workflow-adjustmet
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+185
−14
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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,86 @@ | ||
| name: Backfill GitHub Package Registry | ||
|
|
||
| # Manually triggered. Copies versions already published on npm into the GitHub | ||
| # Package Registry (GPR) so GPR mirrors npm. Re-publishing the npm tarball | ||
| # guarantees the GPR copy is byte-identical to what npm consumers received | ||
| # (no rebuild). | ||
| # | ||
| # dist-tags: each backfilled version is published under the dist-tag npm | ||
| # currently assigns it (latest / v{major}-latest / beta / alpha / rc), so GPR | ||
| # mirrors npm's pointers. Versions npm no longer tags are published under an | ||
| # "imported" tag, which never disturbs `latest`. | ||
| # | ||
| # Idempotent: scripts/publish.sh skips any version already present on GPR, so | ||
| # this can be re-run safely. | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| version: | ||
| description: "Single version to backfill (e.g. 5.3.4). Leave blank to backfill all versions." | ||
| required: false | ||
| default: "" | ||
| dry_run: | ||
| description: "Dry run: report what would be published to GPR without publishing." | ||
| type: boolean | ||
| required: false | ||
| default: false | ||
|
|
||
| jobs: | ||
| backfill: | ||
| name: Backfill npm versions to GPR | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| packages: write | ||
| steps: | ||
| - name: Checkout branch | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: Set up Node | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 18 | ||
|
|
||
| - name: Configure GitHub Package Registry auth | ||
| run: echo "//npm.pkg.github.com/:_authToken=\${NODE_AUTH_TOKEN}" >> ~/.npmrc | ||
| env: | ||
| NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Backfill | ||
| env: | ||
| NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| DRY_RUN: ${{ github.event.inputs.dry_run }} | ||
| INPUT_VERSION: ${{ github.event.inputs.version }} | ||
| run: | | ||
| set -euo pipefail | ||
| pkg="@optimizely/optimizely-sdk" | ||
| npm_registry="https://registry.npmjs.org" | ||
| gpr_registry="https://npm.pkg.github.com" | ||
|
|
||
| if [[ -n "$INPUT_VERSION" ]]; then | ||
| versions="$INPUT_VERSION" | ||
| else | ||
| versions=$(npm view "$pkg" versions --json --registry "$npm_registry" | jq -r '.[]') | ||
| fi | ||
|
|
||
| # Read npm's current dist-tags once and build a version -> tag map, so | ||
| # each backfilled version lands under the same tag it has on npm. | ||
| # `npm dist-tag ls` prints "tag: version" lines. Anything not currently | ||
| # tagged falls back to "imported" (a neutral tag that never moves latest). | ||
| dist_tags_json=$(npm dist-tag ls "$pkg" --registry "$npm_registry" \ | ||
| | jq -R -s 'split("\n") | map(select(length > 0) | split(": ")) | map({(.[1]): .[0]}) | add // {}') | ||
|
|
||
| for v in $versions; do | ||
| echo "::group::${pkg}@${v}" | ||
| tag=$(printf '%s' "$dist_tags_json" | jq -r --arg v "$v" '.[$v] // "imported"') | ||
| # npm pack writes the tarball filename to stdout and notices/errors to | ||
| # stderr; keep stderr visible so pack failures (auth/404/network) show | ||
| # in the logs. pipefail (set above) makes a failed pack abort the job. | ||
| tarball=$(npm pack "${pkg}@${v}" --registry "$npm_registry" | tail -n1) | ||
| scripts/publish.sh "$gpr_registry" "$tarball" "$tag" | ||
| rm -f "$tarball" | ||
| echo "::endgroup::" | ||
| done | ||
|
Comment on lines
+69
to
+86
|
||
This file contains hidden or 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 hidden or 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,60 @@ | ||
| #!/usr/bin/env bash | ||
| # | ||
| # Registry-agnostic, idempotent publish for @optimizely/optimizely-sdk. | ||
| # | ||
| # Usage: | ||
| # scripts/publish.sh <registry-url> <tarball> <dist-tag> | ||
| # | ||
| # Args: | ||
| # registry-url Target registry, e.g. https://registry.npmjs.org | ||
| # or https://npm.pkg.github.com | ||
| # tarball Prebuilt package tarball (output of `npm pack`) to publish. | ||
| # The release flow packs it once and publishes the same bytes to | ||
| # both registries; the backfill packs each version from npm. | ||
| # dist-tag npm dist-tag to publish under. The caller decides the tag; this | ||
| # script is deliberately tag-agnostic so the JS SDK keeps its | ||
| # existing tag logic in the workflow (latest / v{major}-latest / | ||
| # beta / alpha / rc). | ||
| # | ||
| # Env: | ||
| # NODE_AUTH_TOKEN Auth token for the target registry. An .npmrc entry must | ||
| # reference it for <registry-url>'s host, e.g. | ||
| # `//<host>/:_authToken=${NODE_AUTH_TOKEN}` (setup-node writes | ||
| # this for npm; the workflow adds one for GitHub Package | ||
| # Registry). We pass --registry explicitly, so no | ||
| # scope-to-registry routing is needed (and the @optimizely | ||
| # scope is intentionally NOT routed to GPR, so `npm ci` still | ||
| # installs dependencies from npm). | ||
| # DRY_RUN When "true", report the action (publish vs. skip) without | ||
| # actually publishing. | ||
| # | ||
| # Behavior: | ||
| # - Skips (exit 0) if the version already exists on the target registry, so | ||
| # re-running a release or the backfill is always a safe no-op. | ||
| # - Publishes the prebuilt tarball with --ignore-scripts so lifecycle scripts | ||
| # (prepublishOnly = test, prepare = build) don't re-run from package.json. | ||
| set -euo pipefail | ||
|
|
||
| registry="${1:?usage: publish.sh <registry-url> <tarball> <dist-tag>}" | ||
| tarball="${2:?usage: publish.sh <registry-url> <tarball> <dist-tag>}" | ||
| tag="${3:?usage: publish.sh <registry-url> <tarball> <dist-tag>}" | ||
| dry_run="${DRY_RUN:-false}" | ||
|
Comment on lines
+36
to
+41
|
||
|
|
||
| # Derive name/version from the tarball's own package.json so the existence guard | ||
| # matches exactly what we're about to publish. | ||
| meta=$(tar -xzO -f "$tarball" package/package.json) | ||
| pkg=$(printf '%s' "$meta" | jq -r '.name') | ||
| version=$(printf '%s' "$meta" | jq -r '.version') | ||
|
|
||
| if npm view "${pkg}@${version}" version --registry "$registry" >/dev/null 2>&1; then | ||
| echo "Version ${pkg}@${version} already on ${registry}, skipping." | ||
| exit 0 | ||
| fi | ||
|
|
||
| if [[ "$dry_run" == "true" ]]; then | ||
| echo "[dry-run] would publish ${pkg}@${version} (tag: ${tag}) to ${registry}" | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "Publishing ${pkg}@${version} (tag: ${tag}) to ${registry}" | ||
| npm publish "$tarball" --registry "$registry" --tag "$tag" --ignore-scripts | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.