diff --git a/Makefile b/Makefile index 8713a68f009..d38ce6eb5ff 100644 --- a/Makefile +++ b/Makefile @@ -1123,13 +1123,12 @@ init-submodules-e: init-webapps-submodules-e git submodule init e git submodule update -# update-webassets updates the minified code in the webassets repo using the latest webapps -# repo and creates a PR in the teleport repo to update webassets submodule. +# update-webassets creates a PR in the teleport repo to update webassets submodule. .PHONY: update-webassets -update-webassets: WEBAPPS_BRANCH ?= 'master' +update-webassets: WEBASSETS_BRANCH ?= 'master' update-webassets: TELEPORT_BRANCH ?= 'master' update-webassets: - build.assets/webapps/update-teleport-webassets.sh -w $(WEBAPPS_BRANCH) -t $(TELEPORT_BRANCH) + build.assets/webapps/update-teleport-webassets.sh -w $(WEBASSETS_BRANCH) -t $(TELEPORT_BRANCH) # dronegen generates .drone.yml config .PHONY: dronegen diff --git a/build.assets/webapps/README.md b/build.assets/webapps/README.md index c38dce8954c..bda9adcc21e 100644 --- a/build.assets/webapps/README.md +++ b/build.assets/webapps/README.md @@ -3,19 +3,20 @@ ## update-teleport-webassets.sh This script: -- clones the webapps repo + +- clones the `teleport` repo - checks out the provided named branch (after checking that it exists) -- builds the `dist` directory -- clones and pushes updates to `webassets` and `webassets.e` -- raises a PR against the Teleport repo to update the submodule commit references +- raises a PR against the `teleport` repo to update the submodule commit references + +The `webassets` repo is automatically updated for each commit merged to `webapps`. Run using a command like: -`./update-teleport-webassets.sh -w gus/webassets-branch -t gus/teleport-branch` +`./update-teleport-webassets.sh -w teleport-v10 -t branch/v10` | Argument | Description | | - | - | -| `-w` | `webapps` source branch name to build `webassets` from (often `master`) | +| `-w` | `webassets` source branch name to pull `webassets` from (often `master`) | | `-t` | `teleport` target branch name to raise a PR against (often `master`) | ### Extra notes diff --git a/build.assets/webapps/update-teleport-webassets.sh b/build.assets/webapps/update-teleport-webassets.sh index ec4260a60bd..b385ea37f7e 100755 --- a/build.assets/webapps/update-teleport-webassets.sh +++ b/build.assets/webapps/update-teleport-webassets.sh @@ -1,7 +1,7 @@ #!/bin/bash set -euo pipefail -usage() { echo "Usage: $(basename $0) [-w ] [-t ]" 1>&2; exit 1; } +usage() { echo "Usage: $(basename $0) [-w ] [-t ]" 1>&2; exit 1; } while getopts ":w:t:" o; do case "${o}" in w) @@ -21,7 +21,7 @@ if [ -z "${w}" ] || [ -z "${t}" ]; then usage fi -WEBAPPS_BRANCH=${w} +WEBASSETS_BRANCH=${w} TELEPORT_BRANCH=${t} # check if gh is installed @@ -31,12 +31,6 @@ if ! type gh >/dev/null 2>&1; then exit 1 fi -# check if make is installed -if ! type make >/dev/null 2>&1; then - echo "The 'make' utility must be installed to run this script." - exit 1 -fi - # run 'gh auth status' to check if gh config already exists if ! gh auth status; then # log into github via gh tool @@ -47,14 +41,12 @@ if ! gh auth status; then fi # check that the specified remote branches exist -if ! git ls-remote --heads --exit-code git@github.com:gravitational/webapps.git ${WEBAPPS_BRANCH}; then - echo "Cannot find ${WEBAPPS_BRANCH} in the webapps repo." - echo "Make sure that the remote branch has been pushed before running this script." +if ! git ls-remote --heads --exit-code git@github.com:gravitational/webassets.git ${WEBASSETS_BRANCH}; then + echo "Cannot find ${WEBASSETS_BRANCH} in the webassets repo." exit 1 fi if ! git ls-remote --heads --exit-code git@github.com:gravitational/teleport.git ${TELEPORT_BRANCH}; then echo "Cannot find ${TELEPORT_BRANCH} in the teleport repo." - echo "Make sure that the remote branch has been pushed before running this script." exit 1 fi @@ -62,55 +54,6 @@ fi TEMP_DIR="$(mktemp -d)" pushd $TEMP_DIR -# check that specified branch/commit exists in webapps repo -git clone git@github.com:gravitational/webapps.git webapps -pushd webapps -git fetch --all -# try to create target branch -# if it exists, check it out instead -git checkout --track origin/${WEBAPPS_BRANCH} || git checkout ${WEBAPPS_BRANCH} -# init webapps.e repo -git submodule update --init --recursive -# set variables based on context from webapps checkout -BRANCH=$(git rev-parse --abbrev-ref HEAD) -COMMIT=$(git rev-parse --short HEAD) -# use the commit message from webapps, qualifying references to webapps PRs to that they -# link to the correct PR from the teleport repo (#123 becomes gravitational/webapps#123) -COMMIT_DESC=$(git log --decorate=off --oneline -1 | sed -E 's.(#[0-9]+).gravitational/webapps\1.g') -COMMIT_URL="https://github.com/gravitational/webapps/commit/${COMMIT}" -AUTO_BRANCH_NAME="webapps-auto-pr-$(date +%s)" - -# clone webassets repo (into 'webapps/dist') -git clone git@github.com:gravitational/webassets.git dist -pushd dist; git checkout ${BRANCH} || git checkout -b ${BRANCH}; rm -fr ./*/ - -# prepare webassets.e repo (in 'webapps/dist/e') -git submodule update --init --recursive -pushd e; git checkout ${BRANCH} || git checkout -b ${BRANCH}; rm -fr ./*/ -popd; popd - -# build the dist files (in 'webapps') -make build-teleport - -# push dist files to webassets/e repoisitory -pushd dist/e -git add -A . -git commit -am "${COMMIT_DESC}" -m "${COMMIT_URL}" --allow-empty -git push origin ${BRANCH} -popd - -# push dist files to webassets repository -pushd dist -git add -A . -git commit -am "${COMMIT_DESC}" -m "${COMMIT_URL}" --allow-empty -git push origin ${BRANCH} -popd - -# use temporary file to store new webassets commit sha -pushd dist -WEBASSETS_COMMIT_SHA=$(git rev-parse HEAD) -popd - # clone teleport repo git clone git@github.com:gravitational/teleport.git teleport pushd teleport @@ -122,15 +65,16 @@ git checkout --track origin/${TELEPORT_BRANCH} || git checkout ${TELEPORT_BRANCH # update git submodules (webassets/webassets.e) git fetch --recurse-submodules && git submodule update --init webassets -# check out previously committed SHA +AUTO_BRANCH_NAME="webassets-auto-pr-$(date +%s)" +git switch -c ${AUTO_BRANCH_NAME} + pushd webassets -git checkout ${WEBASSETS_COMMIT_SHA} +git switch ${WEBASSETS_BRANCH} +git pull popd -# switch to automatic branch and make a commit -git checkout -b ${AUTO_BRANCH_NAME} -git add -A . -git commit -am "[auto] Update webassets in ${TELEPORT_BRANCH}" -m "${COMMIT_DESC} ${COMMIT_URL}" -m "[source: -w ${WEBAPPS_BRANCH}] [target: -t ${TELEPORT_BRANCH}]" --allow-empty +git add webassets +git commit -am "[auto] Update webassets in teleport/${TELEPORT_BRANCH} from webassets/${WEBASSETS_BRANCH}" --allow-empty git push --set-upstream origin ${AUTO_BRANCH_NAME} # run 'gh' to raise a PR to merge this automatic branch into the target branch