fbshipit-source-id: b14273e883aba6de7b817801a1b04e54a29a6366

This commit is contained in:
Daniel Buchele
2018-06-15 02:23:48 -07:00
parent c6dd46db99
commit 6f95ad512f
12 changed files with 217 additions and 130 deletions

View File

@@ -1,20 +1,68 @@
{
"command": "SandcastleUniversalCommand",
"args": {
"name": "Release public Sonar build",
"oncall": "danielbuechele",
"steps": [
{
"name": "sonar_release_public_build",
"required": true,
"shell": "cd ../xplat/sonar/scripts && ./public-build.sh"
}
]
"name": "Release public Sonar build",
"oncall": "danielbuechele",
"steps": [
{
"name": "Clone from GitHub",
"required": true,
"shell": "git -c http.proxy=fwdproxy:8080 -c https.proxy=fwdproxy:8080 clone https://github.com/facebook/Sonar.git ../xplat/sonar-public"
},
{
"name": "Create Version",
"required": true,
"shell": "cat ../xplat/sonar-public/package.json | jq -r '.version' | sed -E 's/[0-9]+$/__VERSION__/g' > $SANDCASTLE_NEXUS/VERSION"
},
{
"name": "Copy Sandcastle script",
"required": true,
"shell": "cp ../xplat/sonar/scripts/sandcastle-build.sh ../xplat/sonar-public/scripts/sandcastle-build.sh"
},
{
"name": "Create build",
"required": true,
"shell": "cd ../xplat/sonar-public/scripts && ./sandcastle-build.sh $(cat $SANDCASTLE_NEXUS/VERSION)"
},
{
"name": "Copy artifacts for syncing",
"required": true,
"shell": "cp -R ../xplat/sonar-public/dist/Sonar-mac.zip $SANDCASTLE_NEXUS/Sonar-mac.zip"
},
{
"name": "Sync to local",
"step_type": "sync_step",
"from": "remote",
"to": "local",
"paths": [
"Sonar-mac.zip",
"VERSION"
]
},
{
"name": "Publish to github",
"required": true,
"shell": "curl -o RELEASE.json -x fwdproxy:8080 --silent --data '{ \"tag_name\": \"v'$(cat $SANDCASTLE_NEXUS/VERSION)'\", \"target_commitish\": \"master\", \"name\": \"v'$(cat $SANDCASTLE_NEXUS/VERSION)'\", \"body\": \"\", \"draft\": false, \"prerelease\": false}' https://api.github.com/repos/facebook/Sonar/releases?access_token=$(secrets_tool get SONAR_GITHUB_TOKEN)",
"shell_type": "SandcastleLocalShell"
},
{
"name": "Upload",
"required": true,
"shell": "curl -x fwdproxy:8080 $(cat RELEASE.json | jq -r '.upload_url' | sed -e 's#{?name,label}##')'?access_token='$(secrets_tool get SONAR_GITHUB_TOKEN)'&name=Sonar.zip' --header 'Content-Type: application/zip' --upload-file $SANDCASTLE_NEXUS'/Sonar-mac.zip' -X POST",
"shell_type": "SandcastleLocalShell"
}
]
},
"alias": "sonar_release_public_build",
"capabilities": {
"vcs": "fbcode-fbsource",
"type": "lego"
"type": "lego-mac"
},
"hash": "master"
"hash": "master",
"report": [
{
"type": "chirp",
"users": ["__USER__"]
}
]
}

View File

@@ -1,48 +1,24 @@
#!/bin/bash
TOKEN=$(secrets_tool get SONAR_GITHUB_TOKEN)
GITHUB_ORG="facebook"
GITHUB_REPO="Sonar"
cd ../../ || exit
echo "✨ Creating new Sonar release on GitHub..."
MAJOR=$(curl -x fwdproxy:8080 --silent https://raw.githubusercontent.com/facebook/Sonar/master/package.json | jq -r '.version' | sed -E 's/[0-9]+$//g')
function jsonValue() {
python -c 'import json,sys;obj=json.load(sys.stdin);print obj["'$1'"]' || echo ''
}
echo "What should the patch version of the next release be? (v${MAJOR}_)"
git -c http.proxy=fwdproxy:8080 -c https.proxy=fwdproxy:8080 clone https://github.com/facebook/Sonar.git sonar-public
cp sonar/scripts/sandcastle-build.sh sonar-public/scripts/sandcastle-build.sh
# third-party dependencies are not on github, so we need to copy them in place
cp -r sonar/third-party sonar-public/third-party
cd sonar-public/scripts && ./sandcastle-build.sh "$(git rev-list HEAD --count || echo 0)"
VERSION=$(plutil -p ./sonar-public/dist/mac/Sonar.app/Contents/Info.plist | awk '/CFBundleShortVersionString/ {print substr($3, 2, length($3)-2)}')
RELEASE_JSON=$(curl -x fwdproxy:8080 --silent --data '{
"tag_name": "v'$VERSION'",
"target_commitish": "master",
"name": "v'$VERSION'",
"body": "",
"draft": false,
"prerelease": false
}' https://api.github.com/repos/$GITHUB_ORG/$GITHUB_REPO/releases?access_token=$TOKEN)
RELEASE_ID=$(echo $RELEASE_JSON | jsonValue id)
if [ -z "${RELEASE_ID}" ]; then
echo $RELEASE_JSON
exit 1
read -r VERSION
if ! [[ $VERSION =~ ^[0-9]+$ ]] ; then
echo "error: Version needs to be a number" >&2; exit 1
fi
echo "Created GitHub release ID: $RELEASE_ID"
UPLOAD_URL=$(echo $RELEASE_JSON | jsonValue upload_url| sed -e 's#{?name,label}##')
ASSET_JSON=$(curl -x fwdproxy:8080 --silent $UPLOAD_URL'?access_token='$TOKEN'&name=Sonar.zip' --header 'Content-Type: application/zip' --upload-file ./sonar-public/dist/Sonar.zip -X POST)
echo "Creating version $MAJOR$VERSION and releasing to GitHub..."
TMP_DIR=$(mktemp -d)
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
JSON=$(cat "$DIR/public-build.json")
JSON=${JSON/__VERSION__/$VERSION}
JSON=${JSON/__USER__/$USER}
echo "$JSON" > "$TMP_DIR/job.json"
DOWNLOAD_URL=$(echo $ASSET_JSON | jsonValue browser_download_url)
scutil create "$TMP_DIR/job.json"
echo "✅ GitHub release will be automatically created once the Sandcastle job finishes."
if [ -z "${DOWNLOAD_URL}" ]; then
echo $ASSET_JSON
exit 1
fi
echo "Released Sonar v$VERSION"
echo "Download: $DOWNLOAD_URL"
rm -rf "$TMP_DIR"