Skip to content

Commit

Permalink
Merge pull request #178 from Yoast/dist
Browse files Browse the repository at this point in the history
Push to yoast-dist on travis task
  • Loading branch information
noud-github authored May 20, 2021
2 parents 5522ece + ec22d76 commit 101cee5
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ language: php
branches:
only:
- master
- trunk
- develop
- /^release\/*/
- /^hotfix\/\d+\.\d+(\.\d+)?(-\S*)?$/
Expand Down Expand Up @@ -37,6 +38,38 @@ jobs:
env: LINT=1 PHPUNIT=1
- php: "nightly"
env: LINT=1 PHPUNIT=1
- stage: 🚀 deployment
name: "Deploy to Yoast-dist"
php: 7.2
install:
- yarn global add grunt-cli
- yarn install
before_script: skip
script:
- |
if [[ ! -z "$TRAVIS_TAG" ]]; then
grunt set-version -new-version=$TRAVIS_TAG
grunt update-version
fi
- grunt artifact
if: ( tag IS present OR branch =~ /^feature\// OR branch =~ /^release\// OR branch =~ /^hotfix\// OR branch = trunk OR branch = develop ) AND type != pull_request
before_install:
- nvm install lts/*
- curl -o- -L https://yarnpkg.com/install.sh | bash
- export PATH=$HOME/.yarn/bin:$PATH
- openssl aes-256-cbc -K $encrypted_d1beccaa5494_key -iv $encrypted_d1beccaa5494_iv -in config/travis/deploy_keys/id_rsa_yoast_dist.enc -out config/travis/deploy_keys/id_rsa_yoast_dist -d
- chmod 600 config/travis/deploy_keys/id_rsa_yoast_dist
- eval $(ssh-agent -s)
- ssh-add config/travis/deploy_keys/id_rsa_yoast_dist

# If the commit was tagged, create an artifact and push it to the distribution github
deploy:
skip_cleanup: true
provider: script
script: bash config/travis/deploy_to_dist.sh ${TRAVIS_TAG:-$TRAVIS_BRANCH} duplicate-post
on:
repo: $TRAVIS_REPO_SLUG
all_branches: true

allow_failures:
- php: "nightly"
Expand Down
Binary file added config/travis/deploy_keys/id_rsa_yoast_dist.enc
Binary file not shown.
66 changes: 66 additions & 0 deletions config/travis/deploy_to_dist.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env bash

######################
## Deployment script #
######################
## arg 1: git tag ##
## arg 2: repo-name ##
######################

set -ex

if [ -z "$1" ]; then
echo 'The first argument should be the version you want to deploy to dist.'
exit 1
fi

if [ -z "$2" ]; then
echo 'The second argument should be the repo name.'
exit 1
fi

# Repo to deploy to:
USER="Yoast-dist"
REPO=$2
REPO_URL="[email protected]:$USER/$REPO.git"

# Get the latest tag.
lastTag=$1
branch="master"
mainDir=$(pwd)

if [[ $lastTag =~ ^feature/* || $lastTag =~ ^release/* || $lastTag =~ ^hotfix/* || $lastTag == "develop" || $lastTag == "trunk" ]]; then
branch=$lastTag
fi

# Clone the dist repo.
rm -rf ./dist-repo
git clone ${REPO_URL} dist-repo
cd dist-repo
git checkout $branch 2>/dev/null || git checkout -b $branch
cd ..

# Copy the git folder with the entire history.
cp -r ./dist-repo/.git ./artifact
cp composer.json ./artifact

# Remove the vendor directory from the artifact, composer will generate it's own autoload.
rm -rf ./artifact/vendor

# Navigate to the to be committed folder.
cd ./artifact

# Commit the files.
git add -A

# If it's a feature, release or trunk branch.
if [[ $lastTag =~ ^feature/* || $lastTag =~ ^release/* || $lastTag =~ ^hotfix/* || $lastTag == "develop" || $lastTag == "trunk" ]]; then
git commit --allow-empty -m "${TRAVIS_COMMIT_MESSAGE}"
else
git commit -m "Release ${lastTag}"
# Tag the commit.
git tag ${lastTag}
fi

# Push to remote.
git push -u origin $branch --tags

0 comments on commit 101cee5

Please sign in to comment.