Skip to content

Commit cd8dbd1

Browse files
hramosfacebook-github-bot
authored andcommitted
Circle CI: Create GiHub Release draft when bumping version
Summary: Automatically create a GitHub Release draft when a new React Native release is created. The GitHub Release will be created by the same Circle CI job that publishes the package to npm. This job will also upload the built Hermes binaries to the GitHub release. Changelog: [Internal] Reviewed By: cipolleschi Differential Revision: D36646696 fbshipit-source-id: 0a863dc4e3215fc95f7852f8dc43858cdd852aaa
1 parent 8af7870 commit cd8dbd1

File tree

4 files changed

+156
-0
lines changed

4 files changed

+156
-0
lines changed

.circleci/config.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,6 +1217,14 @@ jobs:
12171217
-H "Accept: application/vnd.github.v3+json" \
12181218
-u "$PAT_USERNAME:$PAT_TOKEN" \
12191219
-d "{\"event_type\": \"publish\", \"client_payload\": { \"version\": \"${CIRCLE_TAG:1}\" }}"
1220+
- run:
1221+
name: Install dependencies
1222+
command: apt update && apt install -y jq jo
1223+
- run:
1224+
name: Create draft GitHub Release and upload Hermes binaries
1225+
command: |
1226+
ARTIFACTS=("$HERMES_WS_DIR/hermes-runtime-darwin/hermes-runtime-darwin-$CIRCLE_TAG.tar.gz")
1227+
./scripts/circleci/create_github_release.sh $CIRCLE_TAG $CIRCLE_PROJECT_USERNAME $CIRCLE_PROJECT_REPONAME $GITHUB_TOKEN "${ARTIFACTS[@]}"
12201228
# END: Stable releases
12211229

12221230
# -------------------------

.github/RELEASE_TEMPLATE.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!-- Template for pre-release GitHub release -->
2+
3+
<!-- TODO Post about this release to https://github.com/reactwg/react-native-releases/discussions) -->
4+
5+
- <!-- TODO List out notable picks for this patch -->
6+
7+
---
8+
9+
To test it, run:
10+
11+
npx react-native init RN__SHORT_VERSION__ --version __VERSION__
12+
13+
---
14+
15+
You can participate in the conversation on the status of this release in the [working group](https://github.com/reactwg/react-native-releases/discussions).
16+
17+
---
18+
19+
To help you upgrade to this version, you can use the [upgrade helper](https://react-native-community.github.io/upgrade-helper/) ⚛️
20+
21+
---
22+
23+
See changes from this release in the [changelog PR](https://github.com/facebook/react-native/labels/%F0%9F%93%9D%20Changelog)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
#
4+
# This source code is licensed under the MIT license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
# Add your own Personal Access Token here.
8+
# Create it at https://github.com/settings/tokens
9+
GITHUB_TOKEN=""
10+
11+
# Setup Circle CI envvars
12+
CIRCLE_TAG=""
13+
CIRCLE_PROJECT_USERNAME=""
14+
CIRCLE_PROJECT_REPONAME=""
15+
16+
if [ -z "$GITHUB_TOKEN" ]
17+
then
18+
echo "\$GITHUB_TOKEN is empty"
19+
exit 1
20+
fi
21+
if [ -z "$CIRCLE_TAG" ]
22+
then
23+
echo "\$CIRCLE_TAG is empty"
24+
exit 1
25+
fi
26+
if [ -z "$CIRCLE_PROJECT_USERNAME" ]
27+
then
28+
echo "\$CIRCLE_PROJECT_USERNAME is empty"
29+
exit 1
30+
fi
31+
if [ -z "$CIRCLE_PROJECT_REPONAME" ]
32+
then
33+
echo "\$CIRCLE_PROJECT_REPONAME is empty"
34+
exit 1
35+
fi
36+
37+
# Dummy artifacts to upload
38+
ARTIFACTS=("hermes-runtime-darwin-$CIRCLE_TAG.tar.gz")
39+
for ARTIFACT_PATH in "${ARTIFACTS[@]}"
40+
do
41+
:
42+
head -c 1024 </dev/urandom >"$ARTIFACT_PATH"
43+
done
44+
45+
../circleci/create_github_release.sh "$CIRCLE_TAG" "$CIRCLE_PROJECT_USERNAME" "$CIRCLE_PROJECT_REPONAME" "$GITHUB_TOKEN" "${ARTIFACTS[@]}"
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/bin/bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
#
4+
# This source code is licensed under the MIT license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
GIT_TAG="$1"; shift
8+
GITHUB_OWNER="$1"; shift
9+
GITHUB_REPO="$1"; shift
10+
GITHUB_TOKEN="$1"; shift
11+
ARTIFACTS=("$@")
12+
13+
describe_header () {
14+
printf "\\n\\n>>>>> %s\\n\\n\\n" "$1"
15+
}
16+
17+
describe () {
18+
printf "\\n\\n%s\\n\\n" "$1"
19+
}
20+
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//[.-]/}
27+
28+
PRERELEASE=false
29+
if [[ "$RN_VERSION" == *"rc"* ]]; then
30+
PRERELEASE=true
31+
fi
32+
33+
RELEASE_TEMPLATE_PATH=../../.github/RELEASE_TEMPLATE.md
34+
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)
37+
38+
# 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)
40+
41+
# Create prerelease GitHub Release draft
42+
describe_header "Creating GitHub release."
43+
describe "Release payload: $RELEASE_DATA"
44+
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."
56+
fi
57+
58+
RELEASE_ID=$(echo "$CREATE_RELEASE_RESPONSE" | jq '.id')
59+
60+
# Upload artifacts
61+
for ARTIFACT_PATH in "${ARTIFACTS[@]}"
62+
do
63+
:
64+
# Upload Hermes artifacts to GitHub Release
65+
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
76+
describe "Uploaded $ARTIFACT_NAME."
77+
else
78+
describe "Could not upload $ARTIFACT_NAME to GitHub release."
79+
fi
80+
done

0 commit comments

Comments
 (0)