forked from ampproject/amphtml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🏗 Clean up CircleCI merge SHA logic (ampproject#33215)
- Loading branch information
Showing
7 changed files
with
132 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/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. | ||
|
||
# This script establishes the merge commit at the start of a CircleCI build so | ||
# all stages use the same commit. | ||
|
||
set -e | ||
err=0 | ||
|
||
GREEN() { echo -e "\n\033[0;32m$1\033[0m"; } | ||
|
||
# Try to determine the PR number. | ||
curl -sS https://raw.githubusercontent.com/ampproject/amphtml/master/.circleci/get_pr_number.sh | bash | ||
source $BASH_ENV | ||
|
||
# If PR_NUMBER doesn't exist, there is nothing more to do. | ||
if [[ -z "$PR_NUMBER" ]]; then | ||
exit 0 | ||
fi | ||
|
||
# GitHub provides refs/pull/<PR_NUMBER>/merge, an up-to-date merge branch for | ||
# every PR branch that can be cleanly merged to master. For more details, see: | ||
# https://discuss.circleci.com/t/show-test-results-for-prospective-merge-of-a-github-pr/1662 | ||
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}')" | ||
|
||
echo "$CIRCLE_MERGE_SHA" > .CIRCLECI_MERGE_COMMIT | ||
echo $(GREEN "Stored merge SHA $CIRCLE_MERGE_SHA in .CIRCLECI_MERGE_COMMIT.") | ||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/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. | ||
|
||
# This script extracts the PR number (if there is one) for a CircleCI build. | ||
# Reference: https://circleci.com/docs/2.0/env-vars/#built-in-environment-variables | ||
|
||
set -e | ||
err=0 | ||
|
||
GREEN() { echo -e "\n\033[0;32m$1\033[0m"; } | ||
YELLOW() { echo -e "\n\033[0;33m$1\033[0m"; } | ||
|
||
# Push builds are only run against master and amp-release branches. | ||
if [[ "$CIRCLE_BRANCH" == "master" || "$CIRCLE_BRANCH" =~ ^amp-release-* ]]; then | ||
echo $(GREEN "Nothing to do because $CIRCLE_BRANCH is not a PR branch.") | ||
# Warn if the build is linked to a PR on a different repo (known CircleCI bug). | ||
if [[ -n "$CIRCLE_PULL_REQUEST" && ! "$CIRCLE_PULL_REQUEST" =~ ^https://github.com/ampproject/amphtml* ]]; then | ||
echo $(YELLOW "WARNING: Build is incorrectly linked to a PR outside ampproject/amphtml:") | ||
echo $(YELLOW "$CIRCLE_PULL_REQUEST") | ||
fi | ||
exit 0 | ||
fi | ||
|
||
# CIRCLE_PR_NUMBER is present for PRs originating from forks, but absent for PRs | ||
# originating from a branch on the main repo. In such cases, extract the PR | ||
# number from CIRCLE_PULL_REQUEST. | ||
if [[ "$CIRCLE_PR_NUMBER" ]]; then | ||
PR_NUMBER=$CIRCLE_PR_NUMBER | ||
else | ||
PR_NUMBER=${CIRCLE_PULL_REQUEST#"https://github.com/ampproject/amphtml/pull/"} | ||
fi | ||
|
||
# If neither CIRCLE_PR_NUMBER nor CIRCLE_PULL_REQUEST are available, it's | ||
# possible this is a PR branch that is yet to be associated with a PR. Exit | ||
# early becaue there is no merge commit to fetch. | ||
if [[ -z "$PR_NUMBER" ]]; then | ||
echo $(GREEN "Nothing to do because $CIRCLE_BRANCH is not yet linked to a PR.") | ||
exit 0 | ||
fi | ||
|
||
echo "export PR_NUMBER=$PR_NUMBER" >> $BASH_ENV | ||
echo $(GREEN "This is a PR build for #$PR_NUMBER.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
.DS_Store | ||
.g4ignore | ||
.CIRCLECI_WORKFLOW_MERGE_COMMIT | ||
.CIRCLECI_MERGE_COMMIT | ||
build/ | ||
.amp-dep-check | ||
c | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters