Skip to content

Commit

Permalink
Check GitLab status, instead of GitHub, in release.sh (#1641)
Browse files Browse the repository at this point in the history
* Check GitLab status during release, not GitHub
  • Loading branch information
xbrianh authored Oct 25, 2018
1 parent aca66f4 commit 6ab8864
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 48 deletions.
6 changes: 3 additions & 3 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ release_integration:
script:
- git remote set-url origin https://$GITHUB_TOKEN@github.com/HumanCellAtlas/data-store.git
- for i in $(seq 1 40); do
- status=$(scripts/status.sh HumanCellAtlas dcp integration)
- status=$(scripts/status.py HumanCellAtlas dcp integration)
- if [[ pending != "${status}" && running != "${status}" ]]; then break; fi
- echo "waiting for DCP Integration test to complete";
- sleep 30; # This loop will check status for 20 minutes and then quit
Expand Down Expand Up @@ -157,7 +157,7 @@ release_staging:
script:
- git remote set-url origin https://$GITHUB_TOKEN@github.com/HumanCellAtlas/data-store.git
- for i in $(seq 1 40); do
- status=$(scripts/status.sh HumanCellAtlas dcp staging)
- status=$(scripts/status.py HumanCellAtlas dcp staging)
- if [[ pending != "${status}" && running != "${status}" ]]; then break; fi
- echo "waiting for DCP Integration test to complete";
- sleep 30; # This loop will check status for 20 minutes and then quit
Expand Down Expand Up @@ -189,7 +189,7 @@ release_prod:
script:
- git remote set-url origin https://$GITHUB_TOKEN@github.com/HumanCellAtlas/data-store.git
- for i in $(seq 1 40); do
- status=$(scripts/status.sh HumanCellAtlas dcp prod)
- status=$(scripts/status.py HumanCellAtlas dcp prod)
- if [[ pending != "${status}" && running != "${status}" ]]; then break; fi
- echo "waiting for DCP Integration test to complete";
- sleep 30; # This loop will check status for 20 minutes and then quit
Expand Down
34 changes: 9 additions & 25 deletions scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ set -euo pipefail
if [[ $# > 0 ]]; then
FORCE=
NO_DEPLOY=
SKIP_GITHUB_STATUS=
SKIP_ACCOUNT_VERIFICATION=
POSITIONAL=()
while [[ $# > 0 ]]; do
Expand All @@ -21,10 +20,6 @@ if [[ $# > 0 ]]; then
NO_DEPLOY="--no-deploy"
shift
;;
--skip-github-status)
SKIP_GITHUB_STATUS="--skip-github-status"
shift
;;
--skip-account-verification)
SKIP_ACCOUNT_VERIFICATION="--skip-account-verification"
shift
Expand All @@ -51,13 +46,10 @@ if [[ $# != 2 ]]; then
echo
echo "If the --no-deploy flag is given, the deployment step will be skipped."
echo
echo "If the --skip-github-status flag is given, the combined github status checks"
echo "will be skipped."
echo
echo "If the --skip-account-verification flag is given, the user will not be asked to"
echo "verify cloud account information."
echo
echo "Usage: $(basename $0) source_branch dest_branch [--force] [--no-deploy] [--skip-github-status] [--skip-account-verification]"
echo "Usage: $(basename $0) source_branch dest_branch [--force] [--no-deploy] [--skip-account-verification]"
echo "Example: $(basename $0) master staging"
exit 1
fi
Expand Down Expand Up @@ -101,22 +93,14 @@ fi

export PROMOTE_FROM_BRANCH=$1 PROMOTE_DEST_BRANCH=$2

if [[ $SKIP_GITHUB_STATUS != "--skip-github-status" ]]; then
GH_API=https://api.github.com
REPO=$(git remote get-url origin | perl -ne '/github\.com.(.+?)(\.git)?$/; print $1')
STATUS=$(http GET ${GH_API}/repos/${REPO}/commits/${PROMOTE_FROM_BRANCH}/status Accept:application/vnd.github.full+json)
STATE=$(echo "$STATUS" | jq -r .state)
echo "$STATUS" | jq '.statuses[]|select(.state != "success")'

# TODO: (akislyuk) some CI builds no longer deploy or run a subset of tests. Find the last build that ran a deployment.
if [[ "$STATE" != success ]]; then
if [[ $FORCE == "--force" ]]; then
echo "Status checks failed on branch $PROMOTE_FROM_BRANCH. Forcing promotion and deployment anyway."
else
echo "Status checks failed on branch $PROMOTE_FROM_BRANCH."
echo "Run with --force to promote $PROMOTE_FROM_BRANCH to $PROMOTE_DEST_BRANCH and deploy anyway."
exit 1
fi
STATUS=$(${DSS_HOME}/scripts/status.py HumanCellAtlas data-store $PROMOTE_FROM_BRANCH)
if [[ "$STATUS" != success ]]; then
if [[ $FORCE == "--force" ]]; then
echo "Status checks failed on branch $PROMOTE_FROM_BRANCH. Forcing promotion and deployment anyway."
else
echo "Status checks failed on branch $PROMOTE_FROM_BRANCH."
echo "Run with --force to promote $PROMOTE_FROM_BRANCH to $PROMOTE_DEST_BRANCH and deploy anyway."
exit 1
fi
fi

Expand Down
31 changes: 31 additions & 0 deletions scripts/status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env python
"""
This script outputs GitLab pipeline status.
The GitLab API is expected to be stored in AWS secretsmanager with secret id "dcp/dss/gitlab-api"
The GitLab Token is expected to be stored in AWS secretsmanager with secret id "dcp/dss/gitlab-token"
Usage: `scripts/status.py owner repo branch`
Example: `scripts/status.py HumanCellAtlas data-store master`
"""
import json
import boto3
import requests
import argparse
import urllib.parse

parser = argparse.ArgumentParser()
parser.add_argument("owner", help="The group or owner of the repository")
parser.add_argument("repo", help="The repository name")
parser.add_argument("branch", help="Branch to return most recent CI pipeline status")
args = parser.parse_args()

sm = boto3.client("secretsmanager")

gitlab_api = sm.get_secret_value(SecretId="dcp/dss/gitlab-api")['SecretString']
gitlab_token = sm.get_secret_value(SecretId="dcp/dss/gitlab-token")['SecretString']
slug = urllib.parse.quote_plus(f"{args.owner}/{args.repo}")
r = requests.get(
f"https://{gitlab_api}/projects/{slug}/pipelines",
params={"ref": args.branch},
headers={"Private-Token": gitlab_token},
)
print(json.loads(r.text)[0]['status'])
20 changes: 0 additions & 20 deletions scripts/status.sh

This file was deleted.

0 comments on commit 6ab8864

Please sign in to comment.