Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 49 additions & 21 deletions scripts/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,28 @@
set -e

printusage() {
echo "publish.sh <version>"
echo "publish.sh <version> [branch]"
echo "REPOSITORY_ORG and REPOSITORY_NAME should be set in the environment."
echo "e.g. REPOSITORY_ORG=user, REPOSITORY_NAME=repo"
echo ""
echo "Arguments:"
echo " version: 'patch', 'minor', 'major', or 'artifactsOnly'"
echo " version: 'patch', 'minor', 'major', 'artifactsOnly', or 'preview'"
echo " branch: required if version is 'preview'"
}

VERSION=$1
BRANCH=$2
if [[ $VERSION == "" ]]; then
printusage
exit 1
elif [[ $VERSION == "artifactsOnly" ]]; then
echo "Skipping npm package publish since VERSION is artifactsOnly."
exit 0
elif [[ $VERSION == "preview" ]]; then
if [[ $BRANCH == "" ]]; then
printusage
exit 1
fi
elif [[ ! ($VERSION == "patch" || $VERSION == "minor" || $VERSION == "major") ]]; then
printusage
exit 1
Expand Down Expand Up @@ -61,6 +68,11 @@ echo "Moved to temporary directory."
echo "Cloning repository..."
git clone "git@github.com:${REPOSITORY_ORG}/${REPOSITORY_NAME}.git"
cd "${REPOSITORY_NAME}"
if [[ $VERSION == "preview" ]]; then
echo "Checking out branch $BRANCH..."
git checkout "$BRANCH"
echo "Checked out branch $BRANCH."
fi
echo "Cloned repository."

echo "Making sure there is a changelog..."
Expand All @@ -78,10 +90,18 @@ echo "Running tests..."
npm test
echo "Ran tests."

echo "Making a $VERSION version..."
npm version $VERSION
NEW_VERSION=$(jq -r ".version" package.json)
echo "Made a $VERSION version."
if [[ $VERSION == "preview" ]]; then
echo "Making a preview version..."
sanitized_branch=$(echo "$BRANCH" | sed 's/[^a-zA-Z0-9]/-/g')
npm version prerelease --preid=preview-${sanitized_branch}
NEW_VERSION=$(jq -r ".version" package.json)
echo "Made a preview version."
else
echo "Making a $VERSION version..."
npm version $VERSION
NEW_VERSION=$(jq -r ".version" package.json)
echo "Made a $VERSION version."
fi

echo "Making the release notes..."
RELEASE_NOTES_FILE=$(mktemp)
Expand All @@ -92,23 +112,31 @@ cat CHANGELOG.md >> "${RELEASE_NOTES_FILE}"
echo "Made the release notes."

echo "Publishing to npm..."
npx clean-publish@5.0.0 --before-script ./scripts/clean-shrinkwrap.sh
if [[ $VERSION == "preview" ]]; then
# Note: we publish with a dynamic tag so that this does not become the "latest" version
sanitized_branch=$(echo "$BRANCH" | sed 's/[^a-zA-Z0-9]/-/g')
npx clean-publish@5.0.0 --before-script ./scripts/clean-shrinkwrap.sh --tag=preview-${sanitized_branch}
else
npx clean-publish@5.0.0 --before-script ./scripts/clean-shrinkwrap.sh
fi
echo "Published to npm."

echo "Updating package-lock.json for Docker image..."
npm --prefix ./scripts/publish/firebase-docker-image install
echo "Updated package-lock.json for Docker image."
if [[ $VERSION != "preview" ]]; then
echo "Updating package-lock.json for Docker image..."
npm --prefix ./scripts/publish/firebase-docker-image install
echo "Updated package-lock.json for Docker image."

echo "Cleaning up release notes..."
rm CHANGELOG.md
touch CHANGELOG.md
git commit -m "[firebase-release] Removed change log and reset repo after ${NEW_VERSION} release" CHANGELOG.md scripts/publish/firebase-docker-image/package-lock.json
echo "Cleaned up release notes."
echo "Cleaning up release notes..."
rm CHANGELOG.md
touch CHANGELOG.md
git commit -m "[firebase-release] Removed change log and reset repo after ${NEW_VERSION} release" CHANGELOG.md scripts/publish/firebase-docker-image/package-lock.json
echo "Cleaned up release notes."

echo "Pushing to GitHub..."
git push origin master --tags
echo "Pushed to GitHub."
echo "Pushing to GitHub..."
git push origin master --tags
echo "Pushed to GitHub."

echo "Publishing release notes..."
hub release create --file "${RELEASE_NOTES_FILE}" "v${NEW_VERSION}"
echo "Published release notes."
echo "Publishing release notes..."
hub release create --file "${RELEASE_NOTES_FILE}" "v${NEW_VERSION}"
echo "Published release notes."
fi
49 changes: 42 additions & 7 deletions scripts/publish/cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,15 @@ steps:
# Publish the package.
- name: "gcr.io/$PROJECT_ID/package-builder"
dir: "${_REPOSITORY_NAME}"
args: ["bash", "./scripts/publish.sh", "${_VERSION}"]
entrypoint: bash
args:
- -c
- |
if [ "${_VERSION}" == "preview" ]; then
./scripts/publish.sh "${_VERSION}" "${_BRANCH}"
else
./scripts/publish.sh "${_VERSION}"
fi
env:
- "REPOSITORY_ORG=${_REPOSITORY_ORG}"
- "REPOSITORY_NAME=${_REPOSITORY_NAME}"
Expand All @@ -110,25 +118,51 @@ steps:
# Set up the hub credentials for firepit-builder.
- name: "gcr.io/$PROJECT_ID/firepit-builder"
entrypoint: "bash"
args: ["-c", "mkdir -vp ~/.config && cp -v hub ~/.config/hub"]
args:
- "-c"
- |
if [ "${_VERSION}" != "preview" ]; then
mkdir -vp ~/.config && cp -v hub ~/.config/hub
else
echo "Skipping hub credentials for firepit-builder for preview."
fi

# Publish the firepit builds.
- name: "gcr.io/$PROJECT_ID/firepit-builder"
entrypoint: "node"
args: ["/usr/src/app/pipeline.js", "--package=firebase-tools@latest", "--publish"]
entrypoint: "bash"
args:
- "-c"
- |
if [ "${_VERSION}" != "preview" ]; then
node /usr/src/app/pipeline.js --package=firebase-tools@latest --publish
else
echo "Skipping firepit build for preview version."
fi

# Grab the latest version, store in workspace
- id: "Read New Version Number from npm"
name: "node"
entrypoint: "sh"
args: ["-c", "npm view firebase-tools version > /workspace/version_number.txt"]
args:
- "-c"
- |
if [ "${_VERSION}" != "preview" ]; then
npm view firebase-tools version > /workspace/version_number.txt
else
echo "Skipping version lookup for preview version."
fi

# Publish the Firebase docker image
- name: "gcr.io/cloud-builders/docker"
entrypoint: "sh"
entrypoint: "bash"
args:
- "-c"
- "docker build -t us-docker.pkg.dev/${_ARTIFACT_REGISTRY_PROJECT}/us/firebase:$(cat /workspace/version_number.txt) -t us-docker.pkg.dev/${_ARTIFACT_REGISTRY_PROJECT}/us/firebase:latest -f ./firebase-docker-image/Dockerfile ./firebase-docker-image"
- |
if [ "${_VERSION}" != "preview" ]; then
docker build -t us-docker.pkg.dev/${_ARTIFACT_REGISTRY_PROJECT}/us/firebase:$(cat /workspace/version_number.txt) -t us-docker.pkg.dev/${_ARTIFACT_REGISTRY_PROJECT}/us/firebase:latest -f ./firebase-docker-image/Dockerfile ./firebase-docker-image
else
echo "Skipping docker build for preview version."
fi

images:
- "us-docker.pkg.dev/${_ARTIFACT_REGISTRY_PROJECT}/us/firebase"
Expand All @@ -142,6 +176,7 @@ options:

substitutions:
_VERSION: ""
_BRANCH: ""
_KEY_RING: "cloud-build-ring"
_KEY_NAME: "publish"
_REPOSITORY_ORG: "firebase"
Expand Down
18 changes: 15 additions & 3 deletions scripts/publish/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,33 @@
set -e

printusage() {
echo "run.sh <version>"
echo "run.sh <version> [branch]"
echo ""
echo "Arguments:"
echo " version: 'patch', 'minor', 'major', or 'artifactsOnly'"
echo " version: 'patch', 'minor', 'major', 'artifactsOnly', or 'preview'"
echo " branch: required if version is 'preview'"
}

VERSION=$1
BRANCH=$2
if [[ $VERSION == "" ]]; then
printusage
exit 1
elif [[ $VERSION == "preview" ]]; then
if [[ $BRANCH == "" ]]; then
printusage
exit 1
fi
elif [[ ! ($VERSION == "patch" || $VERSION == "minor" || $VERSION == "major" || $VERSION == "artifactsOnly") ]]; then
printusage
exit 1
fi

SUBSTITUTIONS="_VERSION=$VERSION"
if [[ $VERSION == "preview" ]]; then
SUBSTITUTIONS="$SUBSTITUTIONS,_BRANCH=$BRANCH"
fi

THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

cd "$THIS_DIR"
Expand All @@ -25,5 +37,5 @@ gcloud --project fir-tools-builds \
builds \
submit \
--machine-type=e2-highcpu-8 \
--substitutions=_VERSION=$VERSION \
--substitutions=$SUBSTITUTIONS \
.
Loading