Skip to content

Commit

Permalink
🏗 CircleCI bash file optimizations (ampproject#33734)
Browse files Browse the repository at this point in the history
* Move graceful halt logic into separate file
* Store a copy of the merge commit info file in the workspace
  • Loading branch information
danielrozenberg authored Apr 9, 2021
1 parent 928dd95 commit e9cb065
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
7 changes: 6 additions & 1 deletion .circleci/compute_merge_commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ MERGE_BRANCH="refs/pull/$PR_NUMBER/merge"
echo $(GREEN "Computing merge SHA of $MERGE_BRANCH...")
CIRCLE_MERGE_SHA="$(git ls-remote https://github.com/ampproject/amphtml.git "$MERGE_BRANCH" | awk '{print $1}')"

# TODO(danielrozenberg): after #33708 is submitted, remove local directory copy and only store one in the workspace.
echo "$CIRCLE_MERGE_SHA" > .CIRCLECI_MERGE_COMMIT
echo $(GREEN "Stored merge SHA $CIRCLE_MERGE_SHA in .CIRCLECI_MERGE_COMMIT.")

mkdir -p /tmp/workspace
cp .CIRCLECI_MERGE_COMMIT /tmp/workspace/.CIRCLECI_MERGE_COMMIT

echo $(GREEN "Stored merge SHA $CIRCLE_MERGE_SHA in /tmp/workspace/.CIRCLECI_MERGE_COMMIT.")
exit 0
28 changes: 28 additions & 0 deletions .circleci/maybe_gracefully_halt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
#
# Copyright 2021 The AMP HTML Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS-IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the license.

# Script used by AMP's CI builds to gracefully halt unnecessary jobs, before
# executing time-consuming steps such as checking out the code or installing
# dependencies.

set -e

GREEN() { echo -e "\n\033[0;32m$1\033[0m"; }

if ls /tmp/restored-workspace/.CI_GRACEFULLY_HALT_* 1>/dev/null 2>&1; then
echo $(GREEN "Gracefully halting this job.")
circleci-agent step halt
fi

0 comments on commit e9cb065

Please sign in to comment.