-
Notifications
You must be signed in to change notification settings - Fork 637
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
Migrate publish to gh actions #1312
Closed
Closed
Changes from all commits
Commits
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
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,41 @@ | ||
#!/bin/bash | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
echo "Trying to publish the package to npm for tag $RAW_TAG_NAME" | ||
|
||
# Validate tag's format follows conventions eg v0.1.22 or v0.90.2-alpha.5 | ||
if [[ "$RAW_TAG_NAME" =~ ^v[0-9]+(\.[0-9]+){2}(-.*)?$ ]]; then | ||
echo "The tag is valid."; | ||
else | ||
echo "ERROR: The tag's format is wrong."; | ||
exit 1 | ||
fi | ||
|
||
# Does main contain this tag? (regular release workflow) | ||
TAG_ON_MAIN=$(git branch -a --contains "$RAW_TAG_NAME" | grep -cFx ' remotes/origin/main' || true) | ||
echo "Tag is on main branch: $TAG_ON_MAIN" | ||
|
||
# See https://github.com/facebook/metro/pull/1086 regarding handling of hotfix tags | ||
# Deduce the expected name of a release branch for a tag based on Metro's release branch naming convention, eg v0.1.2-alpha.3 -> 0.1.x | ||
RELEASE_BRANCH=$(echo "$RAW_TAG_NAME" | awk -F. '{print substr($1, 2) "." $2 ".x"}') | ||
|
||
# Does a release branch contain this tag? (hotfix workflow) | ||
git fetch origin ${RELEASE_BRANCH} | ||
TAG_ON_RELEASE_BRANCH=$(git branch -a --contains "$RAW_TAG_NAME" | grep -cFx " remotes/origin/$RELEASE_BRANCH" || true) | ||
echo "Tag is on release branch $RELEASE_BRANCH: $TAG_ON_RELEASE_BRANCH" | ||
|
||
if [ $TAG_ON_RELEASE_BRANCH -eq $TAG_ON_MAIN ]; then | ||
echo "Could not determine whether this tag is 'latest' or a hotfix. Aborting." | ||
exit 1 | ||
fi | ||
|
||
NPM_TAG="latest" | ||
# Use a tag name like "0.123-stable" as the dist-tag for a hotfix. This *must not* be valid semver. | ||
[ "$TAG_ON_RELEASE_BRANCH" -eq 1 ] && NPM_TAG="${RELEASE_BRANCH%.x}-stable" | ||
|
||
echo "Publishing with --tag=$NPM_TAG" | ||
|
||
npm run publish --tag="$NPM_TAG" --dry-run |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to check, will
NPM_TOKEN
be exposed to the code under test at all, e.g. as an env var? Is this secure e.g. against third-party PRs that modify the workflow yaml itself?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As opposed to Circle CI the GH Actions default to be available to this top level yml only. Any secrets that are needed in actions (such as
actions/checkout@v4
or even./.github/actions/yarn-install
above) has to be passed explicitly by passing them as action input or by passingusing secrets: inherit
to the job