Skip to content

Commit

Permalink
Circle CI: Upload both tarballs to releases, dry-run the release work…
Browse files Browse the repository at this point in the history
…flow on every commit (#35015)

Summary:
Pull Request resolved: #35015

React Native releases are cut every few months. Without testing, the workflow is prone to breakage.

Dry-run the release workflow on every commit in order to surface any issues as they are introduced instead of at release time.

Fixed issues that surfaced during testing of this workflow:
- Upload both Hermes tarballs

Changelog: [internal]

Reviewed By: mdvacca

Differential Revision: D40483764

fbshipit-source-id: 5ca6bd4dcdfd64c24882ffb202edbfd701efd462
  • Loading branch information
hramos authored and facebook-github-bot committed Oct 20, 2022
1 parent af0e6cd commit e4b5d3e
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 101 deletions.
95 changes: 80 additions & 15 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1361,6 +1361,9 @@ jobs:
latest:
type: boolean
default: false
dryrun:
type: boolean
default: false
executor: reactnativeios
steps:
- checkout_code_with_cache
Expand All @@ -1373,13 +1376,15 @@ jobs:
- run:
name: "Set new react-native version and commit changes"
command: |
node ./scripts/prepare-package-for-release.js -v << parameters.version >> -l << parameters.latest >>
node ./scripts/prepare-package-for-release.js -v << parameters.version >> -l << parameters.latest >> --dry-run << parameters.dryrun >>
build_npm_package:
parameters:
publish_npm_args:
type: string
default: --dry-run
release_type:
description: The type of release to build. Must be one of "nightly", "release", "dry-run".
type: enum
enum: ["nightly", "release", "dry-run"]
default: "dry-run"
executor: reactnativeandroid
environment:
- HERMES_WS_DIR: *hermes_workspace_root
Expand Down Expand Up @@ -1422,8 +1427,8 @@ jobs:
- when:
condition:
or:
- equal: [ --release, << parameters.publish_npm_args >> ]
- equal: [ --nightly, << parameters.publish_npm_args >> ]
- equal: [ "release", << parameters.release_type >> ]
- equal: [ "nightly", << parameters.release_type >> ]
steps:
- run: echo "//registry.npmjs.org/:_authToken=${CIRCLE_NPM_TOKEN}" > ~/.npmrc
- run: |
Expand All @@ -1432,7 +1437,7 @@ jobs:
echo "machine github.com login react-native-bot password $GITHUB_TOKEN" > ~/.netrc
# END: Stables and nightlies

- run: node ./scripts/publish-npm.js << parameters.publish_npm_args >>
- run: node ./scripts/publish-npm.js --<< parameters.release_type >>
- run:
name: Zip Hermes Native Symbols
command: zip -r /tmp/hermes-native-symbols.zip ~/react-native/ReactAndroid/hermes-engine/build/intermediates/cmake/
Expand All @@ -1443,7 +1448,7 @@ jobs:
# Provide a react-native package for this commit as a Circle CI release artifact.
- when:
condition:
equal: [ --dry-run, << parameters.publish_npm_args >> ]
equal: [ "dry-run", << parameters.release_type >> ]
steps:
- run:
name: Build release package as a job artifact
Expand Down Expand Up @@ -1475,7 +1480,7 @@ jobs:
# START: Stable releases
- when:
condition:
equal: [ --release, << parameters.publish_npm_args >> ]
equal: [ "release", << parameters.release_type >> ]
steps:
- run:
name: Update rn-diff-purge to generate upgrade-support diff
Expand All @@ -1484,15 +1489,44 @@ jobs:
-H "Accept: application/vnd.github.v3+json" \
-u "$PAT_USERNAME:$PAT_TOKEN" \
-d "{\"event_type\": \"publish\", \"client_payload\": { \"version\": \"${CIRCLE_TAG:1}\" }}"
# END: Stable releases

# START: Stables and commitlies
- when:
condition:
or:
- equal: [ "release", << parameters.release_type >> ]
- equal: [ "dry-run", << parameters.release_type >> ]
steps:
- run:
name: Install dependencies
command: apt update && apt install -y jq jo
- run:
name: Create draft GitHub Release and upload Hermes binaries
command: |
ARTIFACTS=("$HERMES_WS_DIR/hermes-runtime-darwin/hermes-runtime-darwin-$CIRCLE_TAG.tar.gz")
./scripts/circleci/create_github_release.sh $CIRCLE_TAG $CIRCLE_PROJECT_USERNAME $CIRCLE_PROJECT_REPONAME $GITHUB_TOKEN "${ARTIFACTS[@]}"
# END: Stable releases
RELEASE_VERSION=$(cat build/.version)
if [[ << parameters.release_type >> == "release" ]]; then
GIT_TAG=$CIRCLE_TAG
elif [[ << parameters.release_type >> == "dry-run" ]]; then
GIT_TAG=v1000.0.0
fi
ARTIFACTS=("")
for build_type in "Debug" "Release"; do
TARBALL_FILENAME=$(node ./scripts/hermes/get-tarball-name.js \
--buildType $build_type \
--releaseVersion $RELEASE_VERSION)
ARTIFACTS+=("$HERMES_WS_DIR/hermes-runtime-darwin/$TARBALL_FILENAME")
done
./scripts/circleci/create_github_release.sh \
<< parameters.release_type >> \
$GIT_TAG \
$RELEASE_VERSION \
$GITHUB_TOKEN \
"${ARTIFACTS[@]}"
# END: Stable and commitlies

# -------------------------
# JOBS: Nightly
Expand Down Expand Up @@ -1551,7 +1585,7 @@ workflows:
- prepare_hermes_workspace
- build_npm_package:
# Build a release package on every untagged commit, but do not publish to npm.
publish_npm_args: --dry-run
release_type: "dry-run"
requires:
- build_hermesc_linux
- build_hermes_macos
Expand Down Expand Up @@ -1639,13 +1673,44 @@ workflows:
- build_npm_package:
name: build_and_publish_npm_package
context: react-native-bot
publish_npm_args: --release
release_type: "release"
filters: *only_release_tags
requires:
- build_hermesc_linux
- build_hermes_macos
- build_hermesc_windows

package_and_publish_release_dryrun:
jobs:
- prepare_package_for_release:
name: prepare_package_for_release
version: 'v1000.0.1'
latest : false
dryrun: true
- prepare_hermes_workspace:
requires:
- prepare_package_for_release
- build_hermesc_linux:
requires:
- prepare_hermes_workspace
- build_hermes_macos:
requires:
- prepare_hermes_workspace
matrix:
parameters:
flavor: ["Debug", "Release"]
- build_hermesc_windows:
requires:
- prepare_hermes_workspace
- build_npm_package:
name: build_and_publish_npm_package
context: react-native-bot
release_type: "dry-run"
requires:
- build_hermesc_linux
- build_hermes_macos
- build_hermesc_windows

analysis:
unless: << pipeline.parameters.run_package_release_workflow_only >>
jobs:
Expand Down Expand Up @@ -1684,7 +1749,7 @@ workflows:
requires:
- prepare_hermes_workspace
- build_npm_package:
publish_npm_args: --nightly
release_type: "nightly"
requires:
- build_hermesc_linux
- build_hermes_macos
Expand Down
45 changes: 0 additions & 45 deletions scripts/__tests__/create_github_release_test.sh

This file was deleted.

123 changes: 83 additions & 40 deletions scripts/circleci/create_github_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,21 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

# This script creates a draft GitHub Release using RELEASE_TEMPLATE.md
# as a template and will upload the provided artifacts to the release.

# Install dependencies:
# apt update && apt install -y jq jo

THIS_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
REACT_NATIVE_PATH="$THIS_DIR/../.."

GITHUB_OWNER=${CIRCLE_PROJECT_USERNAME:-facebook}
GITHUB_REPO=${CIRCLE_PROJECT_REPONAME:-react-native}

RELEASE_TYPE="$1"; shift
GIT_TAG="$1"; shift
GITHUB_OWNER="$1"; shift
GITHUB_REPO="$1"; shift
RELEASE_VERSION="$1"; shift
GITHUB_TOKEN="$1"; shift
ARTIFACTS=("$@")

Expand All @@ -18,63 +30,94 @@ describe () {
printf "\\n\\n%s\\n\\n" "$1"
}

# Format our desired React Native version strings based on incoming git tag parameter.
# GIT_TAG=v0.69.0-rc.4
# 0.69.0-rc.4
RN_VERSION=${GIT_TAG:1}
# 0690rc4
RN_SHORT_VERSION=${RN_VERSION//[.-]/}
echoerr () {
echo "$@" 1>&2
}

PRERELEASE=false
if [[ "$RN_VERSION" == *"rc"* ]]; then
PRERELEASE=true
if [[ $RELEASE_TYPE == "release" ]]; then
describe_header "Preparing to create a GitHub release."
elif [[ $RELEASE_TYPE == "dry-run" ]]; then
describe_header "Preparing to create a GitHub release as a dry-run."
elif [[ $RELEASE_TYPE == "nightly" ]]; then
describe "GitHub Releases are not used with nightlies. Skipping."
exit 0
else
echoerr "Unrecognized release type: $RELEASE_TYPE"
exit 1
fi

RELEASE_TEMPLATE_PATH=../../.github/RELEASE_TEMPLATE.md
# Derive short version string for use in the sample command used
# to create a new RN app in RELEASE_TEMPLATE.md
# 0.69.0-rc.4 -> 0690rc4
RN_SHORT_VERSION=${RELEASE_VERSION//[.-]/}

PRERELEASE=false
if [[ "$RELEASE_VERSION" == *"rc"* ]]; then
PRERELEASE=true
fi

# Replace placeholders in template with actual RN version strings
RELEASE_BODY=$(sed -e "s/__VERSION__/$RN_VERSION/g" -e "s/__SHORT_VERSION__/$RN_SHORT_VERSION/g" $RELEASE_TEMPLATE_PATH)
RELEASE_TEMPLATE_PATH="$REACT_NATIVE_PATH/.github/RELEASE_TEMPLATE.md"
if [[ -f $RELEASE_TEMPLATE_PATH ]]; then
# Replace placeholders in template with actual RN version strings
RELEASE_BODY=$(sed -e "s/__VERSION__/$RELEASE_VERSION/g" -e "s/__SHORT_VERSION__/$RN_SHORT_VERSION/g" "$RELEASE_TEMPLATE_PATH")
else
describe "Could not load GitHub Release template. Falling back to placeholder text."
RELEASE_BODY="<!-- TODO: Fill this out using RELEASE_TEMPLATE.md -->"
fi

# Format and encode JSON payload
RELEASE_DATA=$(jo tag_name="$GIT_TAG" name="$RN_VERSION" body="$RELEASE_BODY" draft=true prerelease="$PRERELEASE" generate_release_notes=false)
RELEASE_DATA=$(jo tag_name="$GIT_TAG" name="$RELEASE_VERSION" body="$RELEASE_BODY" draft=true prerelease="$PRERELEASE" generate_release_notes=false)
if [[ ! $RELEASE_DATA ]]; then
echoerr "Could not format release data."
exit 1
fi

# Create prerelease GitHub Release draft
# Create GitHub Release draft
describe_header "Creating GitHub release."
describe "Release payload: $RELEASE_DATA"

CREATE_RELEASE_RESPONSE=$(curl -X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-d "$RELEASE_DATA" \
"https://api.github.com/repos/$GITHUB_OWNER/$GITHUB_REPO/releases"
)
STATUS=$?
if [ $STATUS == 0 ]; then
describe "Created GitHub release successfully."
else
describe "Could not create GitHub release, request failed with $STATUS."
if [[ $RELEASE_TYPE == "release" ]]; then
CREATE_RELEASE_RESPONSE=$(curl -X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-d "$RELEASE_DATA" \
"https://api.github.com/repos/$GITHUB_OWNER/$GITHUB_REPO/releases"
)
STATUS=$?
if [ $STATUS == 0 ]; then
describe "Created GitHub Release successfully."
RELEASE_ID=$(echo "$CREATE_RELEASE_RESPONSE" | jq '.id')
else
echoerr "Could not create GitHub release, request failed with $STATUS:\n\n$CREATE_RELEASE_RESPONSE"
exit 1
fi
elif [[ $RELEASE_TYPE == "dry-run" ]]; then
describe "Skipping creating GitHub release because dry-run."
fi

RELEASE_ID=$(echo "$CREATE_RELEASE_RESPONSE" | jq '.id')

# Upload artifacts
describe_header "Uploading artifacts to GitHub release."
for ARTIFACT_PATH in "${ARTIFACTS[@]}"
do
:
# Upload Hermes artifacts to GitHub Release
ARTIFACT_NAME=$(basename "$ARTIFACT_PATH")
describe_header "Uploading $ARTIFACT_NAME..."

if curl -X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Content-Length: $(wc -c "$ARTIFACT_PATH" | awk '{print $1}')" \
-H "Content-Type: application/gzip" \
-T "$ARTIFACT_PATH" \
--progress-bar \
"https://uploads.github.com/repos/$GITHUB_OWNER/$GITHUB_REPO/releases/$RELEASE_ID/assets?name=$ARTIFACT_NAME"; then
describe "Uploading $ARTIFACT_NAME..."

if [[ $RELEASE_TYPE == "release" ]]; then
if curl -X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Content-Length: $(wc -c "$ARTIFACT_PATH" | awk '{print $1}')" \
-H "Content-Type: application/gzip" \
-T "$ARTIFACT_PATH" \
--progress-bar \
"https://uploads.github.com/repos/$GITHUB_OWNER/$GITHUB_REPO/releases/$RELEASE_ID/assets?name=$ARTIFACT_NAME"; then
describe "Uploaded $ARTIFACT_NAME."
else
else
describe "Could not upload $ARTIFACT_NAME to GitHub release."
fi
elif [[ $RELEASE_TYPE == "dry-run" ]]; then
describe "Skipping $ARTIFACT_NAME upload because dry-run."
fi
done
1 change: 1 addition & 0 deletions scripts/circleci/post-artifacts-link.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
GITHUB_OWNER=${CIRCLE_PROJECT_USERNAME:-facebook} \
GITHUB_REPO=${CIRCLE_PROJECT_REPONAME:-react-native} \
GITHUB_PR_NUMBER="${CIRCLE_PR_NUMBER:-${CIRCLE_PULL_REQUEST##*/}}" \
GITHUB_REF=${CIRCLE_BRANCH} \
GITHUB_SHA=${CIRCLE_SHA1} \
exec node packages/react-native-bots/post-artifacts-link.js
Loading

0 comments on commit e4b5d3e

Please sign in to comment.