diff --git a/.circleci/config.yml b/.circleci/config.yml index 0e9b4b38187380..fee64be10324af 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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 # ------------------------- diff --git a/.github/RELEASE_TEMPLATE.md b/.github/RELEASE_TEMPLATE.md new file mode 100644 index 00000000000000..302daf94622667 --- /dev/null +++ b/.github/RELEASE_TEMPLATE.md @@ -0,0 +1,23 @@ + + + + +- + +--- + +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) diff --git a/scripts/__tests__/create_github_release_test.sh b/scripts/__tests__/create_github_release_test.sh new file mode 100755 index 00000000000000..da66c1bb684fb9 --- /dev/null +++ b/scripts/__tests__/create_github_release_test.sh @@ -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 "$ARTIFACT_PATH" +done + +../circleci/create_github_release.sh "$CIRCLE_TAG" "$CIRCLE_PROJECT_USERNAME" "$CIRCLE_PROJECT_REPONAME" "$GITHUB_TOKEN" "${ARTIFACTS[@]}" diff --git a/scripts/circleci/create_github_release.sh b/scripts/circleci/create_github_release.sh new file mode 100755 index 00000000000000..27681b83f47c5c --- /dev/null +++ b/scripts/circleci/create_github_release.sh @@ -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