Skip to content

Commit f9a4b30

Browse files
chore: Update dependencies prior D9 upgrade. (#416)
1 parent ea1fb3c commit f9a4b30

37 files changed

Lines changed: 719 additions & 1415 deletions

.github/scripts/build.sh

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
#!/usr/bin/env bash
2+
3+
# Build artifact from the github repo and push it to the hosting provider remote repo.
4+
5+
6+
# Fail immediately when any command fails:
7+
set -e
8+
9+
# Debug output?
10+
if [ "${DEBUG}" == "true" ]; then
11+
set -x
12+
env
13+
fi
14+
15+
# Verify expected variables are defined:
16+
test -n "${GIT_REMOTE}"
17+
test -n "${GIT_SSH_PRIVATE_KEY}"
18+
test -n "${GH_EVENT_REF}"
19+
20+
# Set up private ssh key for git
21+
mkdir ~/.ssh
22+
chmod 700 ~/.ssh
23+
echo "${GIT_SSH_PRIVATE_KEY}" > ~/.ssh/id_rsa
24+
chmod 600 ~/.ssh/id_rsa
25+
26+
git config --global core.sshCommand "ssh -i ~/.ssh/id_rsa -o IdentitiesOnly=yes -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
27+
28+
echo "GITHUB_EVENT_NAME: $GITHUB_EVENT_NAME"
29+
echo "GITHUB_REF: $GITHUB_REF"
30+
echo "GH_EVENT_REF: $GH_EVENT_REF"
31+
echo "GH_EVENT_REF_TYPE: ${GH_EVENT_REF_TYPE}"
32+
33+
# Prepare variables.
34+
FOLDER_GITHUB=$(pwd)
35+
PROJECT_NAME="$(basename `pwd`)"
36+
FOLDER_HOSTING="$FOLDER_GITHUB/../hosting"
37+
mkdir -p $FOLDER_HOSTING
38+
echo "# Github folder: $FOLDER_GITHUB"
39+
echo "# Hosting folder: $FOLDER_HOSTING"
40+
41+
# Figure out who is building.
42+
shalite=$(git rev-parse --short HEAD)
43+
gitname=$(git show -s --format='%an' HEAD)
44+
gitemail=$(git show -s --format='%ae' HEAD)
45+
commitmessage=$(git log -1 --pretty=%B)
46+
if [ "$gitname" == "" ]; then
47+
gitname="Morpht Automation (GitHub Actions)"
48+
gitemail="deployer@morpht.com"
49+
fi
50+
echo "# Name: $gitname"
51+
echo "# Mail: $gitemail"
52+
echo "# SHA: $shalite"
53+
git config --global core.excludesfile false
54+
git config --global core.fileMode true
55+
git config --global user.name "${gitname}"
56+
git config --global user.email "${gitemail}"
57+
58+
# Handling DELETE operation
59+
# This handles deletions of both branches and tags
60+
if [ "$GITHUB_EVENT_NAME" == "delete" ]; then
61+
set -x
62+
cd "$FOLDER_HOSTING"
63+
git clone "$GIT_REMOTE" .
64+
git push --delete origin "${GH_EVENT_REF}"
65+
{ [ "${DEBUG}" ] || set +x; } 2>/dev/null
66+
exit 0
67+
fi
68+
69+
# Assert. We expect the "push" even here, no other events.
70+
if [ "$GITHUB_EVENT_NAME" != "push" ]; then
71+
echo "Unexpected GITHUB_EVENT_NAME: $GITHUB_EVENT_NAME"
72+
exit 1
73+
fi
74+
75+
# The Build
76+
77+
# Install dependencies.
78+
set -x
79+
composer install --prefer-dist --no-progress --no-suggest
80+
{ [ "${DEBUG}" ] || set +x; } 2>/dev/null
81+
82+
# Get current branch name.
83+
BRANCHNAME="$(git rev-parse --symbolic-full-name --abbrev-ref HEAD)"
84+
if [ "$BRANCHNAME" == "HEAD" ]; then
85+
# We are not on a branch, get short commit hash instead.
86+
BRANCHNAME="$(git rev-parse --short HEAD)"
87+
fi
88+
echo "# Resolved branch for a build: $BRANCHNAME."
89+
90+
# Hosting branch name.
91+
92+
# Pantheon requires valid domain name and max 11 characters.
93+
## Replace underscores.
94+
#BRANCHNAME_HOSTING="${BRANCHNAME//_/-}"
95+
## Remove project name from the start
96+
#prefix="${PROJECT_NAME}-"
97+
#BRANCHNAME_HOSTING="${BRANCHNAME//$prefix/}"
98+
## Strip all invalid characters.
99+
#BRANCHNAME_HOSTING="${BRANCHNAME_HOSTING//[^a-zA-Z0-9\-]/}"
100+
## Get first 11 characters.
101+
#BRANCHNAME_HOSTING="$(echo ${BRANCHNAME_HOSTING:0:11})"
102+
103+
# Keep names 1:1 for now to make sure branch delete above works.
104+
# @ToDo: Make this conditional based on external variable
105+
# to allow multiple hosting targets.
106+
BRANCHNAME_HOSTING="$BRANCHNAME-build"
107+
echo "# Hosting branch for a build: $BRANCHNAME_HOSTING."
108+
109+
# Get artefact repo.
110+
echo "FOLDER_HOSTING: $FOLDER_HOSTING"
111+
echo "GIT_REMOTE: $GIT_REMOTE"
112+
echo "BRANCHNAME_HOSTING: $BRANCHNAME_HOSTING"
113+
cd "$FOLDER_HOSTING"
114+
git clone "$GIT_REMOTE" .
115+
git checkout "${BRANCHNAME_HOSTING}" || git checkout -b "${BRANCHNAME_HOSTING}"
116+
117+
# Remove .git and ignores to make sure everything gets committed.
118+
cd $FOLDER_GITHUB
119+
(find . -type d -name ".git" && find . -name ".gitignore" && find . -name ".gitmodules") | xargs rm -rfv
120+
121+
# Swap out .git folders
122+
cp -r "${FOLDER_HOSTING}/.git" .
123+
124+
# Commit new artefact.
125+
git add -A .
126+
git commit -m "${commitmessage}" -m "GitHub build of ${BRANCHNAME} (${BRANCHNAME_HOSTING}) @ ${shalite}." --no-gpg-sign
127+
128+
# Show what changed and push
129+
git show --stat
130+
131+
# Handling PUSH operation
132+
133+
# Handling a tag
134+
if [[ "$GH_EVENT_REF" =~ ^refs\/tags ]]; then
135+
tag_name=${GH_EVENT_REF:10} # cut off the first 10 chars to get tag name
136+
set -x
137+
git push --force origin $tag_name
138+
{ [ "${DEBUG}" ] || set +x; } 2>/dev/null
139+
exit 0
140+
fi
141+
142+
# HEAD will push the current branch
143+
set -x
144+
git push origin "${BRANCHNAME_HOSTING}" --force
145+
{ [ "${DEBUG}" ] || set +x; } 2>/dev/null
146+
exit 0

.github/scripts/synctags.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bash
2+
3+
# Sync tags from the hosting provider repo to this github repo.
4+
5+
6+
# Fail immediately when any command fails:
7+
set -e
8+
9+
# Debug output?
10+
if [ "${DEBUG}" == "true" ]; then
11+
set -x
12+
env
13+
fi
14+
15+
# Verify expected variables are defined:
16+
test -n "${GIT_REMOTE}"
17+
test -n "${GIT_SSH_PRIVATE_KEY}"
18+
19+
# Verify we have this github repo checked out, exit if not:
20+
HAS_CHECKED_OUT_REPO="$(git rev-parse --is-inside-work-tree 2>/dev/null || /bin/true)"
21+
[[ "${HAS_CHECKED_OUT_REPO}" == "true" ]] || exit 1
22+
23+
24+
# Set up private ssh key for git
25+
mkdir ~/.ssh
26+
chmod 700 ~/.ssh
27+
echo "${GIT_SSH_PRIVATE_KEY}" > ~/.ssh/id_rsa
28+
chmod 600 ~/.ssh/id_rsa
29+
30+
git config --global core.sshCommand "ssh -i ~/.ssh/id_rsa -o IdentitiesOnly=yes -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
31+
32+
git remote add hosting "${GIT_REMOTE}"
33+
34+
# fetch tags from the hosting provider repo:
35+
git fetch --tags hosting
36+
# push them to the github repo (which we have checked out).
37+
git push --tags

.github/workflows/build.yml

Lines changed: 33 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,41 @@
1+
---
2+
# Triggers the workflow on push or delete events
3+
on: [push,delete]
14
name: Build
2-
on: [push, pull_request]
35

4-
env:
5-
TRAVIS_BUILD_DIR: ${{ github.workspace }}
6-
COMPOSER_BIN: ${{ github.workspace }}/vendor/bin
7-
BLT_DIR: ${{ github.workspace }}/vendor/acquia/blt
8-
BUILD_DIR: ${{ github.workspace }}
96
jobs:
10-
build:
11-
name: Before install
7+
validate:
8+
name: Validate Composer
129
runs-on: ubuntu-latest
13-
services:
14-
mysql:
15-
image: mysql:5.7
16-
env:
17-
MYSQL_ROOT_PASSWORD: root
18-
ports:
19-
- 3306:3306
2010
steps:
21-
- name: Checkout repository
11+
- name: checkout
12+
uses: actions/checkout@v2
13+
- name: Validate composer.json and composer.lock
14+
if: "!contains(github.ref, 'refs/tags/') && github.event.name != 'delete'"
15+
run: composer validate
16+
# - name: Fail if branch name does not match pantheon limitations
17+
# run: TODO
18+
19+
gitsync:
20+
if: github.ref_name == 'master' || github.ref_name == 'develop'
21+
name: Build and push repo
22+
runs-on: ubuntu-latest
23+
needs: validate
24+
steps:
25+
- name: Checkout.
2226
uses: actions/checkout@v2
23-
- name: Setup PHP version
24-
uses: nanasess/setup-php@v3.0.6
2527
with:
26-
php-version: '7.4'
27-
- name: SSH keys
28-
run: |
29-
# Make private key available from github secrets.
30-
mkdir -p ~/.ssh
31-
rm -fv ~/.ssh/id_rsa
32-
touch ~/.ssh/id_rsa
33-
echo "${{ secrets.CIDRUPALCZPRIVATE }}" >> ~/.ssh/id_rsa
34-
eval "$(ssh-agent -s)"
35-
chmod 700 ~/.ssh/
36-
chmod 600 ~/.ssh/id_rsa
37-
ssh-add ~/.ssh/id_rsa
38-
# Bypass ~/.ssh/known_host and fix "Host key verification failed.".
39-
touch ~/.ssh/config
40-
chmod 600 ~/.ssh/config
41-
echo "Host *" >> ~/.ssh/config
42-
echo " StrictHostKeyChecking no" >> ~/.ssh/config
43-
echo " UserKnownHostsFile=/dev/null" >> ~/.ssh/config
44-
echo " UserKnownHostsFile=/dev/null" >> ~/.ssh/config
45-
- name: Cache composer
46-
uses: actions/cache@v2
28+
fetch-depth: '0'
29+
- name: Setup PHP and tools
30+
uses: shivammathur/setup-php@v2
4731
with:
48-
path: |
49-
$HOME/.composer/cache
50-
vendor
51-
key: composer-${{ hashFiles('**/composer.lock') }}
52-
- name: Install dependencies
53-
run: |
54-
sudo composer self-update --1
55-
composer validate --no-check-all --ansi
56-
composer install --no-suggest
57-
echo ${COMPOSER_BIN} >> $GITHUB_PATH
58-
- name: Verify MySQL connection from host
59-
run: |
60-
sudo apt-get update
61-
sudo apt-get install -y mysql-client
62-
mysql --host 127.0.0.1 --port ${{ job.services.mysql.ports['3306'] }} -uroot -proot -e "select @@hostname;show variables where Variable_name like '%host%';"
63-
mysql --port ${{ job.services.mysql.ports['3306'] }} -uroot -proot --protocol=tcp -e "CREATE DATABASE drupal; CREATE USER 'drupal'@'%' IDENTIFIED BY 'drupal'; GRANT ALL ON drupal.* TO 'drupal'@'%';"
64-
- name: Install chromedriver
65-
run: ${BLT_DIR}/scripts/linux/install-chrome.sh ${COMPOSER_BIN}
66-
- name: Configure git
67-
run: |
68-
git config --global user.name "CI"
69-
git config --global user.email "ci@drupal.cz"
70-
- name: Run tests
71-
run: |
72-
blt validate:all --no-interaction || exit 1
73-
blt setup --define drush.alias='${drush.aliases.ci}' --no-interaction --verbose || exit 1
74-
blt tests:all --define drush.alias='${drush.aliases.ci}' --define tests.run-server=true --no-interaction --verbose || exit 1
75-
- name: Simulate deploy
76-
run: |
77-
blt artifact:deploy --dry-run --commit-msg "Automated commit by CI for Build ${{ github.run_id}}" --no-interaction --verbose
78-
rm -rf deploy
79-
- name: Extract branch name
80-
run: echo "##[set-output name=branch;]$(git branch --show-current)"
81-
id: extract_branch
82-
- name: Run deploy on master and develop
83-
if: ${{ steps.extract_branch.outputs.branch == 'master' || steps.extract_branch.outputs.branch == 'develop' }}
84-
run: |
85-
blt artifact:deploy --commit-msg "Automated commit by CI for Build ${{ github.run_id}}" --branch "${{ steps.extract_branch.outputs.branch }}-build" --no-interaction --verbose
32+
php-version: '7.4'
33+
tools: composer:v1
34+
extensions: mbstring, gd, intl, yaml, bcmath, curl
35+
- name: Execute build script
36+
env:
37+
GIT_REMOTE: ${{ secrets.GIT_REMOTE_HOSTING }}
38+
GIT_SSH_PRIVATE_KEY: ${{ secrets.CIDRUPALCZPRIVATE }}
39+
GH_EVENT_REF: ${{ github.event.ref }}
40+
GH_EVENT_REF_TYPE: ${{ github.event.ref_type }}
41+
run: ./.github/scripts/build.sh

.github/workflows/synctags.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
on: workflow_dispatch
3+
4+
jobs:
5+
6+
tagsync:
7+
name: Sync tags from the hosting repo to the github repo
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout.
11+
uses: actions/checkout@v2
12+
with:
13+
fetch-depth: '0'
14+
- name: Execute sync script
15+
env:
16+
GIT_REMOTE: ${{ secrets.GIT_REMOTE_HOSTING }}
17+
GIT_SSH_PRIVATE_KEY: ${{ secrets.PANTHEON_DEPLOYER_SSH_PRIVATE }}
18+
run: ./.github/scripts/synctags.sh

0 commit comments

Comments
 (0)