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