Skip to content

Commit

Permalink
Circle CI: Create GiHub Release draft when bumping version
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hramos authored and facebook-github-bot committed Jul 14, 2022
1 parent 8af7870 commit cd8dbd1
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,14 @@ jobs:
-H "Accept: application/vnd.github.v3+json" \
-u "$PAT_USERNAME:$PAT_TOKEN" \
-d "{\"event_type\": \"publish\", \"client_payload\": { \"version\": \"${CIRCLE_TAG:1}\" }}"
- 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

# -------------------------
Expand Down
23 changes: 23 additions & 0 deletions .github/RELEASE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!-- Template for pre-release GitHub release -->

<!-- TODO Post about this release to https://github.com/reactwg/react-native-releases/discussions) -->

- <!-- TODO List out notable picks for this patch -->

---

To test it, run:

npx react-native init RN__SHORT_VERSION__ --version __VERSION__

---

You can participate in the conversation on the status of this release in the [working group](https://github.com/reactwg/react-native-releases/discussions).

---

To help you upgrade to this version, you can use the [upgrade helper](https://react-native-community.github.io/upgrade-helper/) ⚛️

---

See changes from this release in the [changelog PR](https://github.com/facebook/react-native/labels/%F0%9F%93%9D%20Changelog)
45 changes: 45 additions & 0 deletions scripts/__tests__/create_github_release_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/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.

# Add your own Personal Access Token here.
# Create it at https://github.com/settings/tokens
GITHUB_TOKEN=""

# Setup Circle CI envvars
CIRCLE_TAG=""
CIRCLE_PROJECT_USERNAME=""
CIRCLE_PROJECT_REPONAME=""

if [ -z "$GITHUB_TOKEN" ]
then
echo "\$GITHUB_TOKEN is empty"
exit 1
fi
if [ -z "$CIRCLE_TAG" ]
then
echo "\$CIRCLE_TAG is empty"
exit 1
fi
if [ -z "$CIRCLE_PROJECT_USERNAME" ]
then
echo "\$CIRCLE_PROJECT_USERNAME is empty"
exit 1
fi
if [ -z "$CIRCLE_PROJECT_REPONAME" ]
then
echo "\$CIRCLE_PROJECT_REPONAME is empty"
exit 1
fi

# Dummy artifacts to upload
ARTIFACTS=("hermes-runtime-darwin-$CIRCLE_TAG.tar.gz")
for ARTIFACT_PATH in "${ARTIFACTS[@]}"
do
:
head -c 1024 </dev/urandom >"$ARTIFACT_PATH"
done

../circleci/create_github_release.sh "$CIRCLE_TAG" "$CIRCLE_PROJECT_USERNAME" "$CIRCLE_PROJECT_REPONAME" "$GITHUB_TOKEN" "${ARTIFACTS[@]}"
80 changes: 80 additions & 0 deletions scripts/circleci/create_github_release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/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.

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

describe_header () {
printf "\\n\\n>>>>> %s\\n\\n\\n" "$1"
}

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//[.-]/}

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

RELEASE_TEMPLATE_PATH=../../.github/RELEASE_TEMPLATE.md

# 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)

# 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)

# Create prerelease 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."
fi

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

# Upload artifacts
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 "Uploaded $ARTIFACT_NAME."
else
describe "Could not upload $ARTIFACT_NAME to GitHub release."
fi
done

0 comments on commit cd8dbd1

Please sign in to comment.