Skip to content

Commit 101cee5

Browse files
authored
Merge pull request #178 from Yoast/dist
Push to yoast-dist on travis task
2 parents 5522ece + ec22d76 commit 101cee5

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed

.travis.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ language: php
44
branches:
55
only:
66
- master
7+
- trunk
78
- develop
89
- /^release\/*/
910
- /^hotfix\/\d+\.\d+(\.\d+)?(-\S*)?$/
@@ -37,6 +38,38 @@ jobs:
3738
env: LINT=1 PHPUNIT=1
3839
- php: "nightly"
3940
env: LINT=1 PHPUNIT=1
41+
- stage: 🚀 deployment
42+
name: "Deploy to Yoast-dist"
43+
php: 7.2
44+
install:
45+
- yarn global add grunt-cli
46+
- yarn install
47+
before_script: skip
48+
script:
49+
- |
50+
if [[ ! -z "$TRAVIS_TAG" ]]; then
51+
grunt set-version -new-version=$TRAVIS_TAG
52+
grunt update-version
53+
fi
54+
- grunt artifact
55+
if: ( tag IS present OR branch =~ /^feature\// OR branch =~ /^release\// OR branch =~ /^hotfix\// OR branch = trunk OR branch = develop ) AND type != pull_request
56+
before_install:
57+
- nvm install lts/*
58+
- curl -o- -L https://yarnpkg.com/install.sh | bash
59+
- export PATH=$HOME/.yarn/bin:$PATH
60+
- 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
61+
- chmod 600 config/travis/deploy_keys/id_rsa_yoast_dist
62+
- eval $(ssh-agent -s)
63+
- ssh-add config/travis/deploy_keys/id_rsa_yoast_dist
64+
65+
# If the commit was tagged, create an artifact and push it to the distribution github
66+
deploy:
67+
skip_cleanup: true
68+
provider: script
69+
script: bash config/travis/deploy_to_dist.sh ${TRAVIS_TAG:-$TRAVIS_BRANCH} duplicate-post
70+
on:
71+
repo: $TRAVIS_REPO_SLUG
72+
all_branches: true
4073

4174
allow_failures:
4275
- php: "nightly"
416 Bytes
Binary file not shown.

config/travis/deploy_to_dist.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env bash
2+
3+
######################
4+
## Deployment script #
5+
######################
6+
## arg 1: git tag ##
7+
## arg 2: repo-name ##
8+
######################
9+
10+
set -ex
11+
12+
if [ -z "$1" ]; then
13+
echo 'The first argument should be the version you want to deploy to dist.'
14+
exit 1
15+
fi
16+
17+
if [ -z "$2" ]; then
18+
echo 'The second argument should be the repo name.'
19+
exit 1
20+
fi
21+
22+
# Repo to deploy to:
23+
USER="Yoast-dist"
24+
REPO=$2
25+
REPO_URL="git@github.com:$USER/$REPO.git"
26+
27+
# Get the latest tag.
28+
lastTag=$1
29+
branch="master"
30+
mainDir=$(pwd)
31+
32+
if [[ $lastTag =~ ^feature/* || $lastTag =~ ^release/* || $lastTag =~ ^hotfix/* || $lastTag == "develop" || $lastTag == "trunk" ]]; then
33+
branch=$lastTag
34+
fi
35+
36+
# Clone the dist repo.
37+
rm -rf ./dist-repo
38+
git clone ${REPO_URL} dist-repo
39+
cd dist-repo
40+
git checkout $branch 2>/dev/null || git checkout -b $branch
41+
cd ..
42+
43+
# Copy the git folder with the entire history.
44+
cp -r ./dist-repo/.git ./artifact
45+
cp composer.json ./artifact
46+
47+
# Remove the vendor directory from the artifact, composer will generate it's own autoload.
48+
rm -rf ./artifact/vendor
49+
50+
# Navigate to the to be committed folder.
51+
cd ./artifact
52+
53+
# Commit the files.
54+
git add -A
55+
56+
# If it's a feature, release or trunk branch.
57+
if [[ $lastTag =~ ^feature/* || $lastTag =~ ^release/* || $lastTag =~ ^hotfix/* || $lastTag == "develop" || $lastTag == "trunk" ]]; then
58+
git commit --allow-empty -m "${TRAVIS_COMMIT_MESSAGE}"
59+
else
60+
git commit -m "Release ${lastTag}"
61+
# Tag the commit.
62+
git tag ${lastTag}
63+
fi
64+
65+
# Push to remote.
66+
git push -u origin $branch --tags

0 commit comments

Comments
 (0)