|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# Script to submit and update feedstock PRs from CircleCI |
| 4 | +# |
| 5 | +# Requires the following environment variables |
| 6 | +# |
| 7 | +# GITHUB_USER: The name of your user or bot |
| 8 | +# CIRCLE_PROJECT_USERNAME: User under which repository is found |
| 9 | +# CIRCLE_PROJECT_REPONAME: Name of repository |
| 10 | +# |
| 11 | +# One of: |
| 12 | +# GITHUB_PASSWORD: Password for user or bot |
| 13 | +# GITHUB_TOKEN: Pre-established token for user or bot |
| 14 | +# |
| 15 | +# One of: |
| 16 | +# CIRCLE_BRANCH: Name of release branch (rel/<version>) |
| 17 | +# CIRCLE_TAG: Name of release tag (<version>) |
| 18 | +# |
| 19 | +# Depends: |
| 20 | +# |
| 21 | +# bash https://www.gnu.org/software/bash/ |
| 22 | +# git https://git-scm.com/ |
| 23 | +# hub https://hub.github.com/ |
| 24 | +# sha256sum https://www.gnu.org/software/coreutils/coreutils.html |
| 25 | +# |
| 26 | +# 2018 Chris Markiewicz |
| 27 | + |
| 28 | +set -x |
| 29 | + |
| 30 | +REPO=${1:-$CIRCLE_PROJECT_REPONAME} |
| 31 | +FEEDSTOCK=${2:-$REPO-feedstock} |
| 32 | + |
| 33 | +SRCREPO=$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME |
| 34 | + |
| 35 | +# Release branches should be of the form 'rel/<version>' |
| 36 | +# The corresponding tag should be the bare '<version>' strings |
| 37 | +if [[ -n "$CIRCLE_TAG" ]]; then |
| 38 | + RELEASE=true |
| 39 | + REF="$CIRCLE_TAG" |
| 40 | + BRANCH="rel/$REF" |
| 41 | + VERSION="$REF" |
| 42 | + COMMIT_MSG="REL: $VERSION" |
| 43 | + PR_TITLE="REL: $VERSION" |
| 44 | +else |
| 45 | + RELEASE=false |
| 46 | + REF="$CIRCLE_BRANCH" |
| 47 | + BRANCH=$REF |
| 48 | + VERSION="${REF#rel/}" |
| 49 | + COMMIT_MSG="TEST: $BRANCH" |
| 50 | + PR_TITLE="[WIP] REL: $VERSION" |
| 51 | +fi |
| 52 | + |
| 53 | +# Clean working copy |
| 54 | +TMP=`mktemp -d` |
| 55 | +hub clone conda-forge/$FEEDSTOCK $TMP/$FEEDSTOCK |
| 56 | +pushd $TMP/$FEEDSTOCK |
| 57 | + |
| 58 | +# Get user fork, move to a candidate release branch, detecting if new branch |
| 59 | +hub fork |
| 60 | +git fetch --all |
| 61 | +if git checkout -t $GITHUB_USER/$BRANCH; then |
| 62 | + NEW_PR=false |
| 63 | +else |
| 64 | + NEW_PR=true |
| 65 | + git checkout -b $BRANCH origin/master |
| 66 | +fi |
| 67 | + |
| 68 | +# Calculate hash |
| 69 | +SHA256=`curl -sSL https://github.com/$SRCREPO/archive/$BRANCH.tar.gz | sha256sum | cut -d\ -f 1` |
| 70 | + |
| 71 | +# Set version, hash, and reset build number |
| 72 | +# Use ~ for separator, as it's an invalid character in a git-ref |
| 73 | +sed -i '' \ |
| 74 | + -e 's~^\({% set version = "\).*\(" %}\)$~'"\1$REF\2~" \ |
| 75 | + -e 's/^\({% set sha256 = "\).*\(" %}\)$/'"\1$SHA256\2/" \ |
| 76 | + -e 's/^\( *number:\) .*$/\1 0/' \ |
| 77 | + recipe/meta.yaml |
| 78 | + |
| 79 | +# Bump branch |
| 80 | +git add recipe/meta.yaml |
| 81 | +git commit -m "$COMMIT_MSG" |
| 82 | +git push -u $GITHUB_USER $BRANCH |
| 83 | + |
| 84 | +if $NEW_PR; then |
| 85 | + hub pull-request -b conda-forge:master -F - <<END; |
| 86 | +$PR_TITLE |
| 87 | +
|
| 88 | +Updating feedstock to release branch |
| 89 | +
|
| 90 | +#### Environment |
| 91 | +
|
| 92 | +| Variable | Value | |
| 93 | +|----------|-------| |
| 94 | +| `CIRCLE_PROJECT_USERNAME` | $CIRCLE_PROJECT_USERNAME | |
| 95 | +| `CIRCLE_PROJECT_REPONAME` | $CIRCLE_PROJECT_REPONAME | |
| 96 | +| `CIRCLE_BRANCH` | $CIRCLE_BRANCH | |
| 97 | +| `CIRCLE_TAG` | $CIRCLE_TAG | |
| 98 | +
|
| 99 | +#### Calculated values |
| 100 | +
|
| 101 | +| URL | https://github.com/$SRCREPO/archive/$BRANCH.tar.gz | |
| 102 | +| SHA256 | $SHA256 | |
| 103 | +END; |
| 104 | +fi |
| 105 | + |
| 106 | +# Remove working copy |
| 107 | +popd |
| 108 | +rm -rf $TMP/$FEEDSTOCK |
0 commit comments