Skip to content

Commit e4b5d3e

Browse files
hramosfacebook-github-bot
authored andcommitted
Circle CI: Upload both tarballs to releases, dry-run the release workflow 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
1 parent af0e6cd commit e4b5d3e

6 files changed

+184
-101
lines changed

.circleci/config.yml

+80-15
Original file line numberDiff line numberDiff line change
@@ -1361,6 +1361,9 @@ jobs:
13611361
latest:
13621362
type: boolean
13631363
default: false
1364+
dryrun:
1365+
type: boolean
1366+
default: false
13641367
executor: reactnativeios
13651368
steps:
13661369
- checkout_code_with_cache
@@ -1373,13 +1376,15 @@ jobs:
13731376
- run:
13741377
name: "Set new react-native version and commit changes"
13751378
command: |
1376-
node ./scripts/prepare-package-for-release.js -v << parameters.version >> -l << parameters.latest >>
1379+
node ./scripts/prepare-package-for-release.js -v << parameters.version >> -l << parameters.latest >> --dry-run << parameters.dryrun >>
13771380
13781381
build_npm_package:
13791382
parameters:
1380-
publish_npm_args:
1381-
type: string
1382-
default: --dry-run
1383+
release_type:
1384+
description: The type of release to build. Must be one of "nightly", "release", "dry-run".
1385+
type: enum
1386+
enum: ["nightly", "release", "dry-run"]
1387+
default: "dry-run"
13831388
executor: reactnativeandroid
13841389
environment:
13851390
- HERMES_WS_DIR: *hermes_workspace_root
@@ -1422,8 +1427,8 @@ jobs:
14221427
- when:
14231428
condition:
14241429
or:
1425-
- equal: [ --release, << parameters.publish_npm_args >> ]
1426-
- equal: [ --nightly, << parameters.publish_npm_args >> ]
1430+
- equal: [ "release", << parameters.release_type >> ]
1431+
- equal: [ "nightly", << parameters.release_type >> ]
14271432
steps:
14281433
- run: echo "//registry.npmjs.org/:_authToken=${CIRCLE_NPM_TOKEN}" > ~/.npmrc
14291434
- run: |
@@ -1432,7 +1437,7 @@ jobs:
14321437
echo "machine github.com login react-native-bot password $GITHUB_TOKEN" > ~/.netrc
14331438
# END: Stables and nightlies
14341439

1435-
- run: node ./scripts/publish-npm.js << parameters.publish_npm_args >>
1440+
- run: node ./scripts/publish-npm.js --<< parameters.release_type >>
14361441
- run:
14371442
name: Zip Hermes Native Symbols
14381443
command: zip -r /tmp/hermes-native-symbols.zip ~/react-native/ReactAndroid/hermes-engine/build/intermediates/cmake/
@@ -1443,7 +1448,7 @@ jobs:
14431448
# Provide a react-native package for this commit as a Circle CI release artifact.
14441449
- when:
14451450
condition:
1446-
equal: [ --dry-run, << parameters.publish_npm_args >> ]
1451+
equal: [ "dry-run", << parameters.release_type >> ]
14471452
steps:
14481453
- run:
14491454
name: Build release package as a job artifact
@@ -1475,7 +1480,7 @@ jobs:
14751480
# START: Stable releases
14761481
- when:
14771482
condition:
1478-
equal: [ --release, << parameters.publish_npm_args >> ]
1483+
equal: [ "release", << parameters.release_type >> ]
14791484
steps:
14801485
- run:
14811486
name: Update rn-diff-purge to generate upgrade-support diff
@@ -1484,15 +1489,44 @@ jobs:
14841489
-H "Accept: application/vnd.github.v3+json" \
14851490
-u "$PAT_USERNAME:$PAT_TOKEN" \
14861491
-d "{\"event_type\": \"publish\", \"client_payload\": { \"version\": \"${CIRCLE_TAG:1}\" }}"
1492+
# END: Stable releases
1493+
1494+
# START: Stables and commitlies
1495+
- when:
1496+
condition:
1497+
or:
1498+
- equal: [ "release", << parameters.release_type >> ]
1499+
- equal: [ "dry-run", << parameters.release_type >> ]
1500+
steps:
14871501
- run:
14881502
name: Install dependencies
14891503
command: apt update && apt install -y jq jo
14901504
- run:
14911505
name: Create draft GitHub Release and upload Hermes binaries
14921506
command: |
1493-
ARTIFACTS=("$HERMES_WS_DIR/hermes-runtime-darwin/hermes-runtime-darwin-$CIRCLE_TAG.tar.gz")
1494-
./scripts/circleci/create_github_release.sh $CIRCLE_TAG $CIRCLE_PROJECT_USERNAME $CIRCLE_PROJECT_REPONAME $GITHUB_TOKEN "${ARTIFACTS[@]}"
1495-
# END: Stable releases
1507+
RELEASE_VERSION=$(cat build/.version)
1508+
if [[ << parameters.release_type >> == "release" ]]; then
1509+
GIT_TAG=$CIRCLE_TAG
1510+
elif [[ << parameters.release_type >> == "dry-run" ]]; then
1511+
GIT_TAG=v1000.0.0
1512+
fi
1513+
1514+
ARTIFACTS=("")
1515+
for build_type in "Debug" "Release"; do
1516+
TARBALL_FILENAME=$(node ./scripts/hermes/get-tarball-name.js \
1517+
--buildType $build_type \
1518+
--releaseVersion $RELEASE_VERSION)
1519+
1520+
ARTIFACTS+=("$HERMES_WS_DIR/hermes-runtime-darwin/$TARBALL_FILENAME")
1521+
done
1522+
1523+
./scripts/circleci/create_github_release.sh \
1524+
<< parameters.release_type >> \
1525+
$GIT_TAG \
1526+
$RELEASE_VERSION \
1527+
$GITHUB_TOKEN \
1528+
"${ARTIFACTS[@]}"
1529+
# END: Stable and commitlies
14961530

14971531
# -------------------------
14981532
# JOBS: Nightly
@@ -1551,7 +1585,7 @@ workflows:
15511585
- prepare_hermes_workspace
15521586
- build_npm_package:
15531587
# Build a release package on every untagged commit, but do not publish to npm.
1554-
publish_npm_args: --dry-run
1588+
release_type: "dry-run"
15551589
requires:
15561590
- build_hermesc_linux
15571591
- build_hermes_macos
@@ -1639,13 +1673,44 @@ workflows:
16391673
- build_npm_package:
16401674
name: build_and_publish_npm_package
16411675
context: react-native-bot
1642-
publish_npm_args: --release
1676+
release_type: "release"
16431677
filters: *only_release_tags
16441678
requires:
16451679
- build_hermesc_linux
16461680
- build_hermes_macos
16471681
- build_hermesc_windows
16481682

1683+
package_and_publish_release_dryrun:
1684+
jobs:
1685+
- prepare_package_for_release:
1686+
name: prepare_package_for_release
1687+
version: 'v1000.0.1'
1688+
latest : false
1689+
dryrun: true
1690+
- prepare_hermes_workspace:
1691+
requires:
1692+
- prepare_package_for_release
1693+
- build_hermesc_linux:
1694+
requires:
1695+
- prepare_hermes_workspace
1696+
- build_hermes_macos:
1697+
requires:
1698+
- prepare_hermes_workspace
1699+
matrix:
1700+
parameters:
1701+
flavor: ["Debug", "Release"]
1702+
- build_hermesc_windows:
1703+
requires:
1704+
- prepare_hermes_workspace
1705+
- build_npm_package:
1706+
name: build_and_publish_npm_package
1707+
context: react-native-bot
1708+
release_type: "dry-run"
1709+
requires:
1710+
- build_hermesc_linux
1711+
- build_hermes_macos
1712+
- build_hermesc_windows
1713+
16491714
analysis:
16501715
unless: << pipeline.parameters.run_package_release_workflow_only >>
16511716
jobs:
@@ -1684,7 +1749,7 @@ workflows:
16841749
requires:
16851750
- prepare_hermes_workspace
16861751
- build_npm_package:
1687-
publish_npm_args: --nightly
1752+
release_type: "nightly"
16881753
requires:
16891754
- build_hermesc_linux
16901755
- build_hermes_macos

scripts/__tests__/create_github_release_test.sh

-45
This file was deleted.

scripts/circleci/create_github_release.sh

+83-40
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,21 @@
44
# This source code is licensed under the MIT license found in the
55
# LICENSE file in the root directory of this source tree.
66

7+
# This script creates a draft GitHub Release using RELEASE_TEMPLATE.md
8+
# as a template and will upload the provided artifacts to the release.
9+
10+
# Install dependencies:
11+
# apt update && apt install -y jq jo
12+
13+
THIS_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
14+
REACT_NATIVE_PATH="$THIS_DIR/../.."
15+
16+
GITHUB_OWNER=${CIRCLE_PROJECT_USERNAME:-facebook}
17+
GITHUB_REPO=${CIRCLE_PROJECT_REPONAME:-react-native}
18+
19+
RELEASE_TYPE="$1"; shift
720
GIT_TAG="$1"; shift
8-
GITHUB_OWNER="$1"; shift
9-
GITHUB_REPO="$1"; shift
21+
RELEASE_VERSION="$1"; shift
1022
GITHUB_TOKEN="$1"; shift
1123
ARTIFACTS=("$@")
1224

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

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

28-
PRERELEASE=false
29-
if [[ "$RN_VERSION" == *"rc"* ]]; then
30-
PRERELEASE=true
37+
if [[ $RELEASE_TYPE == "release" ]]; then
38+
describe_header "Preparing to create a GitHub release."
39+
elif [[ $RELEASE_TYPE == "dry-run" ]]; then
40+
describe_header "Preparing to create a GitHub release as a dry-run."
41+
elif [[ $RELEASE_TYPE == "nightly" ]]; then
42+
describe "GitHub Releases are not used with nightlies. Skipping."
43+
exit 0
44+
else
45+
echoerr "Unrecognized release type: $RELEASE_TYPE"
46+
exit 1
3147
fi
3248

33-
RELEASE_TEMPLATE_PATH=../../.github/RELEASE_TEMPLATE.md
49+
# Derive short version string for use in the sample command used
50+
# to create a new RN app in RELEASE_TEMPLATE.md
51+
# 0.69.0-rc.4 -> 0690rc4
52+
RN_SHORT_VERSION=${RELEASE_VERSION//[.-]/}
53+
54+
PRERELEASE=false
55+
if [[ "$RELEASE_VERSION" == *"rc"* ]]; then
56+
PRERELEASE=true
57+
fi
3458

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

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

41-
# Create prerelease GitHub Release draft
75+
# Create GitHub Release draft
4276
describe_header "Creating GitHub release."
4377
describe "Release payload: $RELEASE_DATA"
4478

45-
CREATE_RELEASE_RESPONSE=$(curl -X POST \
46-
-H "Accept: application/vnd.github.v3+json" \
47-
-H "Authorization: Bearer $GITHUB_TOKEN" \
48-
-d "$RELEASE_DATA" \
49-
"https://api.github.com/repos/$GITHUB_OWNER/$GITHUB_REPO/releases"
50-
)
51-
STATUS=$?
52-
if [ $STATUS == 0 ]; then
53-
describe "Created GitHub release successfully."
54-
else
55-
describe "Could not create GitHub release, request failed with $STATUS."
79+
if [[ $RELEASE_TYPE == "release" ]]; then
80+
CREATE_RELEASE_RESPONSE=$(curl -X POST \
81+
-H "Accept: application/vnd.github.v3+json" \
82+
-H "Authorization: Bearer $GITHUB_TOKEN" \
83+
-d "$RELEASE_DATA" \
84+
"https://api.github.com/repos/$GITHUB_OWNER/$GITHUB_REPO/releases"
85+
)
86+
STATUS=$?
87+
if [ $STATUS == 0 ]; then
88+
describe "Created GitHub Release successfully."
89+
RELEASE_ID=$(echo "$CREATE_RELEASE_RESPONSE" | jq '.id')
90+
else
91+
echoerr "Could not create GitHub release, request failed with $STATUS:\n\n$CREATE_RELEASE_RESPONSE"
92+
exit 1
93+
fi
94+
elif [[ $RELEASE_TYPE == "dry-run" ]]; then
95+
describe "Skipping creating GitHub release because dry-run."
5696
fi
5797

58-
RELEASE_ID=$(echo "$CREATE_RELEASE_RESPONSE" | jq '.id')
59-
6098
# Upload artifacts
99+
describe_header "Uploading artifacts to GitHub release."
61100
for ARTIFACT_PATH in "${ARTIFACTS[@]}"
62101
do
63102
:
64103
# Upload Hermes artifacts to GitHub Release
65104
ARTIFACT_NAME=$(basename "$ARTIFACT_PATH")
66-
describe_header "Uploading $ARTIFACT_NAME..."
67-
68-
if curl -X POST \
69-
-H "Accept: application/vnd.github.v3+json" \
70-
-H "Authorization: Bearer $GITHUB_TOKEN" \
71-
-H "Content-Length: $(wc -c "$ARTIFACT_PATH" | awk '{print $1}')" \
72-
-H "Content-Type: application/gzip" \
73-
-T "$ARTIFACT_PATH" \
74-
--progress-bar \
75-
"https://uploads.github.com/repos/$GITHUB_OWNER/$GITHUB_REPO/releases/$RELEASE_ID/assets?name=$ARTIFACT_NAME"; then
105+
describe "Uploading $ARTIFACT_NAME..."
106+
107+
if [[ $RELEASE_TYPE == "release" ]]; then
108+
if curl -X POST \
109+
-H "Accept: application/vnd.github.v3+json" \
110+
-H "Authorization: Bearer $GITHUB_TOKEN" \
111+
-H "Content-Length: $(wc -c "$ARTIFACT_PATH" | awk '{print $1}')" \
112+
-H "Content-Type: application/gzip" \
113+
-T "$ARTIFACT_PATH" \
114+
--progress-bar \
115+
"https://uploads.github.com/repos/$GITHUB_OWNER/$GITHUB_REPO/releases/$RELEASE_ID/assets?name=$ARTIFACT_NAME"; then
76116
describe "Uploaded $ARTIFACT_NAME."
77-
else
117+
else
78118
describe "Could not upload $ARTIFACT_NAME to GitHub release."
119+
fi
120+
elif [[ $RELEASE_TYPE == "dry-run" ]]; then
121+
describe "Skipping $ARTIFACT_NAME upload because dry-run."
79122
fi
80123
done

scripts/circleci/post-artifacts-link.sh

+1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
GITHUB_OWNER=${CIRCLE_PROJECT_USERNAME:-facebook} \
88
GITHUB_REPO=${CIRCLE_PROJECT_REPONAME:-react-native} \
99
GITHUB_PR_NUMBER="${CIRCLE_PR_NUMBER:-${CIRCLE_PULL_REQUEST##*/}}" \
10+
GITHUB_REF=${CIRCLE_BRANCH} \
1011
GITHUB_SHA=${CIRCLE_SHA1} \
1112
exec node packages/react-native-bots/post-artifacts-link.js

0 commit comments

Comments
 (0)