Skip to content

Commit

Permalink
Merge branch 'improved-bitbucket-support' of https://github.com/phill…
Browse files Browse the repository at this point in the history
…tran/terminus-build-tools-plugin into philltran-improved-bitbucket-support
  • Loading branch information
greg-1-anderson committed Oct 1, 2018
2 parents 9ab4c01 + 26f3ab6 commit 2ae40ea
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 16 deletions.
29 changes: 25 additions & 4 deletions .circleci/config.yml
@@ -1,9 +1,31 @@
# https://circleci.com/docs/2.0/workflows/#using-workspaces-to-share-data-among-jobs
defaults: &defaults
docker:
- image: quay.io/pantheon-public/php-ci:latest
- image: quay.io/philltran/docker-build-tools-ci
working_directory: ~/terminus_build_tools_plugin
environment:

#=========================================================================
# In addition to the environment variables defined in this file, also
# add the following variables in the Circle CI UI.
#
# See: https://circleci.com/docs/2.0/env-vars/
#
# TERMINUS_SITE: Name of the Pantheon site to run tests on, e.g. my_site
# TERMINUS_TOKEN: The Pantheon machine token
# TERMINUS_ORG: Name of Pantheon Agency / Team
# CIRCLE_TOKEN: Circle CI Token
# GITHUB_TOKEN: The GitHub personal access token
# GITHUB_USER: The GitHub username
# GIT_EMAIL: The email address to use when making commits
# BITBUCKET_USER: The Bitbucket Username
# BITBUCKET_PASS: The Bitbucket app specific password
#
# TEST_SITE_NAME: The name of the test site to provide when installing.
# ADMIN_PASSWORD: The admin password to use when installing.
# ADMIN_EMAIL: The email address to give the admin when installing.
#=========================================================================

BASH_ENV: ~/.bashrc
TZ: "/usr/share/zoneinfo/America/Los_Angeles"
TERM: dumb
Expand Down Expand Up @@ -54,9 +76,8 @@ jobs:
name: dependencies
command: ./.circleci/set-up-globals.sh
- run:
name: Test D8 with BitBucket (unfinished)
command: echo "Disabling this test until it is passing."
# command: ./.circleci/test-example-repo.sh "pantheon-systems/example-drops-8-composer:dev-test-2.x" bitbucket
name: Test D8 with BitBucket
command: ./.circleci/test-example-repo.sh "pantheon-systems/example-drops-8-composer:dev-master" bitbucket
- run:
name: D8 with Bitbucket Build Failed
when: on_fail
Expand Down
5 changes: 2 additions & 3 deletions .circleci/test-example-repo.sh
Expand Up @@ -51,8 +51,7 @@ if [ "$GIT_PROVIDER" == "github" ]; then
else
if [ "$GIT_PROVIDER" == "bitbucket" ]; then
TARGET_REPO=$BITBUCKET_USER/$TERMINUS_SITE
# Bitbucket repo is private, thus HTTP basic auth is integrated into clone URL
CLONE_URL="https://$BITBUCKET_USER:$BITBUCKET_PASS@bitbucket.org/${TARGET_REPO}.git"
CLONE_URL="https://$BITBUCKET_USER@bitbucket.org/${TARGET_REPO}.git"
else
echo "Unsupported GIT_PROVIDER. Valid values are: github, bitbucket"
exit 1
Expand All @@ -62,7 +61,7 @@ fi
terminus build:project:create -n "$SOURCE_COMPOSER_PROJECT" "$TERMINUS_SITE" --git=$GIT_PROVIDER --team="$TERMINUS_ORG" --email="$GIT_EMAIL" --env="BUILD_TOOLS_VERSION=$BUILD_TOOLS_VERSION"
# Confirm that the Pantheon site was created
terminus site:info "$TERMINUS_SITE"
# Confirm that the Github project was created
# Confirm that the Github or Bitbucket project was created
git clone "$CLONE_URL" "$TARGET_REPO_WORKING_COPY"
# Confirm that Circle was configured for testing, and that the first test passed.

Expand Down
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -27,6 +27,7 @@ In order to use this plugin, you will need to set up a GitHub repository and a C
In order to use the build:project:create command, the first thing that you need to do is set up credentials to access GitHub and Circle CI. Instructions on creating these credentials can be found on the pages listed below:

- GitHub: https://help.github.com/articles/creating-an-access-token-for-command-line-use/
- Bitbucket: https://confluence.atlassian.com/bitbucket/app-passwords-828781300.html
- Circle CI: https://circleci.com/account/api

The GitHub token needs the "repo" and "delete repo" scopes.
Expand All @@ -36,6 +37,8 @@ These credentials may be exported as environment variables. For example:
#!/bin/bash
export GITHUB_TOKEN=[REDACTED]
export CIRCLE_TOKEN=[REDACTED]
export BITBUCKET_USER=[REDACTED]
export BITBUCKET_PASS=[REDACTED]
```
If you do not export these environment variables, you will be prompted to enter them when you run the build:project:create command. Credentials that you enter will be cached in the ~/.terminus/cache folder; `terminus self:cc` will erase cached credentials.

Expand Down
2 changes: 1 addition & 1 deletion src/Commands/EnvObliterateCommand.php
Expand Up @@ -65,7 +65,7 @@ public function obliterate($site_name)

// Delete the remote git repository.
$gitProvider->deleteRepository($project);
$this->log()->notice('Deleted {project} from GitHub', ['project' => $project,]);
$this->log()->notice('Deleted {project} from ' . $GIT_PROVIDER, ['project' => $project,]);

// Use the Terminus API to delete the Pantheon site.
$site->delete();
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/ProjectCreateCommand.php
Expand Up @@ -385,7 +385,7 @@ function ($state) use ($ci_env, $siteDir) {
->progressMessage('Set up CI services')

// Set up CircleCI to test our project.
// Note taht this also modifies the README and commits it to the repository.
// Note that this also modifies the README and commits it to the repository.
->taskCISetup()
->provider($this->ci_provider)
->environment($ci_env)
Expand Down
Expand Up @@ -142,15 +142,17 @@ public function authenticatedUser()
/**
* @inheritdoc
*/
public function createRepository($local_site_path, $target, $github_org = '')
public function createRepository($local_site_path, $target, $org = '')
{
// Username for Bitbucket API is either provider $github_org
// repository id must be lower case.
$target = strtolower($target);

// Username for Bitbucket API is either provider $org
// or username
$target_org = $github_org;
if (empty($github_org)) {
$target_org = $this->getBitBucketUser();
if (empty($org)) {
$org = $this->getBitBucketUser();
}
$target_project = "$target_org/$target";
$target_project = "$org/$target";

// Create a Bitbucket repository
$this->logger->notice('Creating repository {repo}', ['repo' => $target_project]);
Expand Down
2 changes: 1 addition & 1 deletion src/Task/CI/Setup.php
Expand Up @@ -29,7 +29,7 @@ public function run()

$circleBadge = $this->provider->badge($this->ci_env);

// Replace the 'ci | none' badge with the Circle bagde. If
// Replace the 'ci | none' badge with the Circle badge. If
// there is no badge placeholder, then put the Circle badge
// near the front of the README, ideally after the '# Project Title'.
if (preg_match('#!\[CI none\]\([^)]*\)#', $readme)) {
Expand Down

0 comments on commit 2ae40ea

Please sign in to comment.