Skip to content
Open
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
4 changes: 2 additions & 2 deletions scripts/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ BRANCH=$2
if [[ $VERSION == "" ]]; then
printusage
exit 1
elif [[ $VERSION == "artifactsOnly" ]]; then
echo "Skipping npm package publish since VERSION is artifactsOnly."
elif [[ $VERSION == "artifactsOnly" || $VERSION == "firepitOnly" || $VERSION == "dockerOnly" ]]; then
echo "Skipping npm package publish since VERSION is $VERSION."
exit 0
elif [[ $VERSION == "preview" ]]; then
if [[ $BRANCH == "" ]]; then
Expand Down
91 changes: 63 additions & 28 deletions scripts/publish/cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,47 @@ steps:
entrypoint: "bash"
args: ["-c", "mkdir -vp ~/.config && cp -v hub ~/.config/hub"]

# Determine version number for artifactsOnly, firepitOnly, or dockerOnly modes.
- name: "gcr.io/$PROJECT_ID/package-builder"
entrypoint: "bash"
args:
- "-c"
- |
if [[ "${_VERSION}" == "artifactsOnly" || "${_VERSION}" == "firepitOnly" || "${_VERSION}" == "dockerOnly" ]]; then
if [[ -n "${_VERSION_NUMBER}" ]]; then
echo "${_VERSION_NUMBER}" > /workspace/version_number.txt
else
npm view firebase-tools version > /workspace/version_number.txt
fi
VERSION_NUM=$(cat /workspace/version_number.txt)
echo "Using version number: $VERSION_NUM"

# Update the package-lock.json for the docker image to use the target version
DOCKER_DIR="./firebase-docker-image"
if [[ ! -d "$DOCKER_DIR" ]]; then
DOCKER_DIR="./scripts/publish/firebase-docker-image"
fi
if [[ ! -d "$DOCKER_DIR" ]]; then
DOCKER_DIR="./firebase-tools/scripts/publish/firebase-docker-image"
fi
npm --prefix "$DOCKER_DIR" install firebase-tools@$VERSION_NUM
fi
Comment thread
joehan marked this conversation as resolved.

# Publish the package.
- name: "gcr.io/$PROJECT_ID/package-builder"
dir: "${_REPOSITORY_NAME}"
entrypoint: bash
args:
- -c
- |
if [ "${_VERSION}" == "preview" ]; then
./scripts/publish.sh "${_VERSION}" "${_BRANCH}"
if [[ "${_VERSION}" == "patch" || "${_VERSION}" == "minor" || "${_VERSION}" == "major" || "${_VERSION}" == "preview" ]]; then
if [ "${_VERSION}" == "preview" ]; then
./scripts/publish.sh "${_VERSION}" "${_BRANCH}"
else
GITHUB_TOKEN=$(cat ~/.config/hub) ./scripts/publish.sh "${_VERSION}"
fi
else
GITHUB_TOKEN=$(cat ~/.config/hub) ./scripts/publish.sh "${_VERSION}"
echo "Skipping package publish step for ${_VERSION} mode."
fi
env:
- "REPOSITORY_ORG=${_REPOSITORY_ORG}"
Expand All @@ -117,34 +147,38 @@ steps:
args:
- "-c"
- |
echo "Waiting for firebase-tools@$(cat /workspace/version_number.txt) to be available on npm..."
timeout=300
elapsed=0
interval=15
until npm install --dry-run "firebase-tools@$(cat /workspace/version_number.txt)" > /dev/null 2>&1; do
if [ $$elapsed -ge $$timeout ]; then
echo "Timeout waiting for package."
exit 1
fi
echo "Still waiting..."
sleep $$interval
elapsed=$$((elapsed + interval))
done
echo "Sleeping for 60 seconds to ensure propagation..."
sleep 60
echo "Package firebase-tools@$(cat /workspace/version_number.txt) is now available on npm."
if [[ "${_VERSION}" == "patch" || "${_VERSION}" == "minor" || "${_VERSION}" == "major" || "${_VERSION}" == "preview" ]]; then
echo "Waiting for firebase-tools@$(cat /workspace/version_number.txt) to be available on npm..."
timeout=300
elapsed=0
interval=15
until npm install --dry-run "firebase-tools@$(cat /workspace/version_number.txt)" > /dev/null 2>&1; do
if [ $$elapsed -ge $$timeout ]; then
echo "Timeout waiting for package."
exit 1
fi
echo "Still waiting..."
sleep $$interval
elapsed=$$((elapsed + interval))
done
echo "Sleeping for 60 seconds to ensure propagation..."
sleep 60
echo "Package firebase-tools@$(cat /workspace/version_number.txt) is now available on npm."
else
echo "Skipping wait for npm package step for ${_VERSION} mode."
fi

# Set up the hub and npm credentials for firepit-builder.
- name: "gcr.io/$PROJECT_ID/firepit-builder"
entrypoint: "bash"
args:
- "-c"
- |
if [ "${_VERSION}" != "preview" ]; then
if [[ "${_VERSION}" == "patch" || "${_VERSION}" == "minor" || "${_VERSION}" == "major" || "${_VERSION}" == "artifactsOnly" || "${_VERSION}" == "firepitOnly" ]]; then
mkdir -vp ~/.config && cp -v hub ~/.config/hub
cp -v npmrc ~/.npmrc
else
echo "Skipping credentials for firepit-builder for preview."
echo "Skipping credentials for firepit-builder for ${_VERSION} mode."
fi

# Publish the firepit builds.
Expand All @@ -153,11 +187,11 @@ steps:
args:
- "-c"
- |
if [ "${_VERSION}" != "preview" ]; then
if [[ "${_VERSION}" == "patch" || "${_VERSION}" == "minor" || "${_VERSION}" == "major" || "${_VERSION}" == "artifactsOnly" || "${_VERSION}" == "firepitOnly" ]]; then
GITHUB_TOKEN=$(cat ~/.config/hub) node /usr/src/app/pipeline.js --package=firebase-tools@$(cat /workspace/version_number.txt) --publish
echo "Please review the draft release notes at https://github.com/${_REPOSITORY_ORG}/${_REPOSITORY_NAME}/releases. If it looks good, publish it"
else
echo "Skipping firepit build for preview version."
echo "Skipping firepit build for ${_VERSION} mode."
fi

# Tag the previous version of the docker image
Expand All @@ -166,7 +200,7 @@ steps:
args:
- "-c"
- |
if [ "${_VERSION}" != "preview" ]; then
if [[ "${_VERSION}" == "patch" || "${_VERSION}" == "minor" || "${_VERSION}" == "major" || "${_VERSION}" == "artifactsOnly" || "${_VERSION}" == "dockerOnly" ]]; then
IMAGE_NAME="us-docker.pkg.dev/${_ARTIFACT_REGISTRY_PROJECT}/us/firebase"
TAGS=$(gcloud container images list-tags $${IMAGE_NAME} --filter="tags:latest" --format="value(tags)")
echo "Tags for latest: $${TAGS}"
Expand All @@ -178,7 +212,7 @@ steps:
echo "Could not detect previous version tag. Skipping tagging."
fi
else
echo "Skipping for preview version."
echo "Skipping docker tagging step for ${_VERSION} mode."
fi

# Publish the Firebase docker image
Expand All @@ -187,20 +221,20 @@ steps:
args:
- "-c"
- |
if [ "${_VERSION}" != "preview" ]; then
if [[ "${_VERSION}" == "patch" || "${_VERSION}" == "minor" || "${_VERSION}" == "major" || "${_VERSION}" == "artifactsOnly" || "${_VERSION}" == "dockerOnly" ]]; then
set -e
VERSION_NUM="$$(cat /workspace/version_number.txt)"
REPO="us-docker.pkg.dev/${_ARTIFACT_REGISTRY_PROJECT}/us/firebase"
docker build -t "$${REPO}:$${VERSION_NUM}" -t "$${REPO}:latest" -f ./firebase-docker-image/Dockerfile ./firebase-docker-image
docker push "$${REPO}:$${VERSION_NUM}"
else
echo "Skipping docker build for preview version."
echo "Skipping docker build step for ${_VERSION} mode."
fi

images:
- "us-docker.pkg.dev/${_ARTIFACT_REGISTRY_PROJECT}/us/firebase"

timeout: 1200s # 20 minutes
timeout: 3600s # 60 minutes

options:
volumes:
Expand All @@ -210,6 +244,7 @@ options:
substitutions:
_VERSION: ""
_BRANCH: ""
_VERSION_NUMBER: ""
_KEY_RING: "cloud-build-ring"
_KEY_NAME: "publish"
_REPOSITORY_ORG: "firebase"
Expand Down
40 changes: 36 additions & 4 deletions scripts/publish/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,44 @@
set -e

printusage() {
echo "run.sh <version> [branch]"
echo "run.sh <version> [branch/options]"
echo ""
echo "Arguments:"
echo " version: 'patch', 'minor', 'major', 'artifactsOnly', or 'preview'"
echo " version: 'patch', 'minor', 'major', 'artifactsOnly', 'firepitOnly', 'dockerOnly', or 'preview'"
echo " branch: required if version is 'preview'"
echo " --version-number <num>: optional for 'artifactsOnly', 'firepitOnly', 'dockerOnly'"
}

VERSION=$1
BRANCH=$2
shift || true

BRANCH=""
VERSION_NUMBER=""

if [[ $VERSION == "preview" ]]; then
BRANCH=$1
shift || true
fi

while [[ $# -gt 0 ]]; do
case $1 in
--version-number)
if [[ -z "$2" ]]; then
echo "Error: --version-number requires a version argument."
printusage
exit 1
fi
VERSION_NUMBER="$2"
shift 2
;;
Comment thread
joehan marked this conversation as resolved.
*)
echo "Unknown argument: $1"
printusage
exit 1
;;
esac
done

if [[ $VERSION == "" ]]; then
printusage
exit 1
Expand All @@ -19,7 +48,7 @@ elif [[ $VERSION == "preview" ]]; then
printusage
exit 1
fi
elif [[ ! ($VERSION == "patch" || $VERSION == "minor" || $VERSION == "major" || $VERSION == "artifactsOnly") ]]; then
elif [[ ! ($VERSION == "patch" || $VERSION == "minor" || $VERSION == "major" || $VERSION == "artifactsOnly" || $VERSION == "firepitOnly" || $VERSION == "dockerOnly") ]]; then
printusage
exit 1
fi
Expand All @@ -28,6 +57,9 @@ SUBSTITUTIONS="_VERSION=$VERSION"
if [[ $VERSION == "preview" ]]; then
SUBSTITUTIONS="$SUBSTITUTIONS,_BRANCH=$BRANCH"
fi
if [[ -n "$VERSION_NUMBER" ]]; then
SUBSTITUTIONS="$SUBSTITUTIONS,_VERSION_NUMBER=$VERSION_NUMBER"
fi

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

Expand Down
Loading