Skip to content

Merge pull request #842 from SLAC/main #1833

Merge pull request #842 from SLAC/main

Merge pull request #842 from SLAC/main #1833

name: Build, deploy and test
on:
push:
branches:
- integration
- migration
- main
- live
- uat
defaults:
run:
shell: bash
env:
TZ: "/usr/share/zoneinfo/America/Los_Angeles"
NOTIFY: 'scripts/github/add-commit-comment {project} {sha} "Created multidev environment [{site}#{env}]({dashboard-url})." {site-url}'
TERM: dumb
ADMIN_EMAIL: ${{ secrets.ADMIN_EMAIL }}
ADMIN_PASSWORD: ${{ secrets.ADMIN_PASSWORD }}
ADMIN_USERNAME: ${{ secrets.ADMIN_USERNAME }}
GITHUB_TOKEN: ${{ github.token }}
TERMINUS_TOKEN: ${{ secrets.TERMINUS_TOKEN }}
TEST_SITE_NAME: ${{ secrets.TERMINUS_SITE }}
CI_BRANCH: ${{ github.ref }}
COMMIT_SHA: ${{ github.sha }}
CI_BUILD_NUMBER: ${{ github.run_number }}
DEFAULT_SITE: ${{ secrets.TERMINUS_SITE }}
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
GITHUB_OWNER: ${{ github.repository_owner }}
CI_PROJECT_NAME: ${{ github.repository }}
jobs:
configure_env_vars:
container:
image: quay.io/pantheon-public/build-tools-ci:8.x-php8.0
options: --user root
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set bash_env env var
run: echo BASH_ENV=${RUNNER_TEMP}/bash_env.txt >> $GITHUB_ENV
- name: Cache bash_env.txt
uses: actions/cache@v2
env:
cache-name: cache-bash-env
with:
path: ${{ env.BASH_ENV }}
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ github.run_number }}
# Set TERMINUS_ENV and related environment variables.
# https://github.com/pantheon-systems/docker-build-tools-ci/blob/6.x/scripts/set-environment
- name: setup-environment-vars
run: |
if [ "$CI_BRANCH" != "refs/heads/master" ]; then
export PR_NUMBER=`curl -u "${GITHUB_OWNER}:${GITHUB_TOKEN}" \
-H "Accept: application/vnd.github.groot-preview+json" \
"https://api.github.com/repos/${CI_PROJECT_NAME}/commits/${COMMIT_SHA}/pulls" | \
python3 -c "import sys, json; print(json.load(sys.stdin)[0]['number'])"`
export CI_BRANCH=`curl -u "${GITHUB_OWNER}:${GITHUB_TOKEN}" \
-H "Accept: application/vnd.github.groot-preview+json" \
"https://api.github.com/repos/${CI_PROJECT_NAME}/commits/${COMMIT_SHA}/pulls" | \
python3 -c "import sys, json; print(json.load(sys.stdin)[0]['head']['ref'])"`
export CI_PULL_REQUEST=`curl -u "${GITHUB_OWNER}:${GITHUB_TOKEN}" \
-H "Accept: application/vnd.github.groot-preview+json" \
"https://api.github.com/repos/${CI_PROJECT_NAME}/commits/${COMMIT_SHA}/pulls" | \
python3 -c "import sys, json; print(json.load(sys.stdin)[0]['html_url'])"`
else
export CI_BRANCH="master"
fi
export CI_PROJECT_REPONAME=`curl -u "${GITHUB_OWNER}:${GITHUB_TOKEN}" \
-H "Accept: application/vnd.github.groot-preview+json" \
"https://api.github.com/repos/${CI_PROJECT_NAME}/commits/${COMMIT_SHA}/pulls" | \
python3 -c "import sys, json; print(json.load(sys.stdin)[0]['base']['repo']['name'])"`
export CI_PROJECT_USERNAME=$GITHUB_REPOSITORY_OWNER
/build-tools-ci/scripts/set-environment
GITHUB_WORKFLOW_URL=https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID
echo "export CI_BUILD_URL='${GITHUB_WORKFLOW_URL}'" >> $BASH_ENV
echo "export CI_NODE_INDEX=0" >> $BASH_ENV
echo "export CI_REPOSITORY_URL='https://github.com/${GITHUB_REPOSITORY}'" >> $BASH_ENV
echo "export ARTIFACTS_DIR_URL='${GITHUB_WORKFLOW_URL}/#artifacts'" >> $BASH_ENV
static_tests:
container:
image: quay.io/pantheon-public/build-tools-ci:8.x-php8.0
options: --user root
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Cache composer cache
uses: actions/cache@v2
env:
cache-name: cache-composer-cache
with:
path: ~/.composer/cache
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
# Set TERMINUS_ENV and related environment variables.
# https://github.com/pantheon-systems/docker-build-tools-ci/blob/6.x/scripts/set-environment
- name: setup-environment-vars
run: /build-tools-ci/scripts/set-environment
- name: run static tests
run: |
./.ci/test/static/run
# If needed, frontend assets compilation or similar steps
# could be added here.
build_gesso:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 14
- run: |
cd web/themes/gesso
npm ci
npm run build-storybook
- uses: actions/upload-artifact@v3
with:
name: gesso-dist-files
path: |
web/themes/gesso/dist
web/themes/gesso/storybook
deploy_to_pantheon:
container:
image: pantheonpublic/build-tools-ci@sha256:15b244fdfeb225541a5eef4801a4abdebd2d4b8146cd472329d75226b10a87e5
options: --user root
runs-on: ubuntu-latest
needs: [configure_env_vars, static_tests, build_gesso]
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/download-artifact@v3
with:
name: gesso-dist-files
path: web/themes/gesso
- name: Display structure of downloaded files
run: ls -R
working-directory: web/themes/gesso
- name: Set bash_env env var
run: echo BASH_ENV=${RUNNER_TEMP}/bash_env.txt >> $GITHUB_ENV
- name: Cache bash_env.txt
uses: actions/cache@v2
env:
cache-name: cache-bash-env
with:
path: ${{ env.BASH_ENV }}
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ github.run_number }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Cache composer cache
uses: actions/cache@v2
env:
cache-name: cache-composer-cache
with:
path: ~/.composer/cache
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Cache vendor folder
uses: actions/cache@v2
env:
cache-name: cache-vendor
with:
path: ./vendor
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/composer.lock') }}
- name: Cache web folder
uses: actions/cache@v2
env:
cache-name: cache-web
with:
path: ./web
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ github.run_number }}
- name: Cache drush folder
uses: actions/cache@v2
env:
cache-name: cache-drush
with:
path: ./drush
key: ${{ runner.os }}-build-${{ env.cache-name }}
# Set TERMINUS_ENV and related environment variables.
# https://github.com/pantheon-systems/docker-build-tools-ci/blob/6.x/scripts/set-environment
- name: setup-environment-vars
run: /build-tools-ci/scripts/set-environment
- name: override-environment-vars
run: ./.ci/deploy/pantheon/override-environment-vars
# Deploy to Pantheon
- name: deploy to Pantheon
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
echo "$SSH_PRIVATE_KEY" > ../private.key
chmod 600 ../private.key
eval `ssh-agent -s`
ssh-add ../private.key
source $BASH_ENV
./.ci/deploy/pantheon/dev-multidev
# behat_test:
# container:
# image: quay.io/pantheon-public/build-tools-ci:8.x-php7.4
# options: --user root
# runs-on: ubuntu-latest
# continue-on-error: true
# needs: [deploy_to_pantheon]
# steps:
# - name: Checkout
# uses: actions/checkout@v2
# - name: Set bash_env env var
# run: echo BASH_ENV=${RUNNER_TEMP}/bash_env.txt >> $GITHUB_ENV
# - name: Cache bash_env.txt
# uses: actions/cache@v2
# env:
# cache-name: cache-bash-env
# with:
# path: ${{ env.BASH_ENV }}
# key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ github.run_number }}
# restore-keys: |
# ${{ runner.os }}-build-${{ env.cache-name }}-
# ${{ runner.os }}-build-
# ${{ runner.os }}-
# - name: Cache composer cache
# uses: actions/cache@v2
# env:
# cache-name: cache-composer-cache
# with:
# path: ~/.composer/cache
# key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/composer.lock') }}
# restore-keys: |
# ${{ runner.os }}-build-${{ env.cache-name }}-
# ${{ runner.os }}-build-
# ${{ runner.os }}-
# - name: Cache vendor folder
# uses: actions/cache@v2
# env:
# cache-name: cache-vendor
# with:
# path: ./vendor
# key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/composer.lock') }}
# - name: Cache web folder
# uses: actions/cache@v2
# env:
# cache-name: cache-web
# with:
# path: ./web
# key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ github.run_number }}
# - name: Cache drush folder
# uses: actions/cache@v2
# env:
# cache-name: cache-drush
# with:
# path: ./drush
# key: ${{ runner.os }}-build-${{ env.cache-name }}
# # Set TERMINUS_ENV and related environment variables.
# # https://github.com/pantheon-systems/docker-build-tools-ci/blob/6.x/scripts/set-environment
# - name: setup-environment-vars
# run: /build-tools-ci/scripts/set-environment
# # Uncomment line 26 in .ci/test/behat/initialize to create a backup
# # prior to running Behat tests. This is useful to reset the multidev
# # environment to the previous state after Behat tests have run.
# - name: prepare for Behat testing
# run: |
# echo "$SSH_PRIVATE_KEY" > ../private.key
# chmod 600 ../private.key
# eval `ssh-agent -s`
# ssh-add ../private.key
# source $BASH_ENV
# ./.ci/test/behat/initialize
# - name: run acceptance tests with Behat
# run: |
# eval `ssh-agent -s`
# ssh-add ../private.key
# ./.ci/test/behat/run
# # Uncomment line 13 in .ci/test/behat/cleanup to restore a backup
# # after running Behat tests. This is useful to reset the multidev
# # environment to the previous state after Behat tests have run.
# - name: clean up after Behat
# if: ${{ always() }}
# run: |
# eval `ssh-agent -s`
# ssh-add ../private.key
# source $BASH_ENV
# ./.ci/test/behat/cleanup
# - name: Upload artifacts
# if: ${{ always() }}
# uses: actions/upload-artifact@v2
# with:
# name: behat-report
# path: /tmp/artifacts
# visual_regression_test:
# container:
# image: backstopjs/backstopjs:5.3.2
# options: --user root
# runs-on: ubuntu-latest
# if: ${{ github.ref != 'refs/heads/master' }}
# needs: [configure_env_vars, behat_test]
# steps:
# - name: Update git version
# run: |
# echo "deb http://ppa.launchpad.net/git-core/ppa/ubuntu xenial main" >> /etc/apt/sources.list
# apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys E1DD270288B4E6030699E45FA1715D88E1DF1F24
# apt update -y
# apt install -y git
# - name: Checkout
# uses: actions/checkout@v2
# with:
# fetch-depth: 0
# - name: Set bash_env env var
# run: echo BASH_ENV=${RUNNER_TEMP}/bash_env.txt >> $GITHUB_ENV
# - name: Cache bash_env.txt
# uses: actions/cache@v2
# env:
# cache-name: cache-bash-env
# with:
# path: ${{ env.BASH_ENV }}
# key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ github.run_number }}
# restore-keys: |
# ${{ runner.os }}-build-${{ env.cache-name }}-
# ${{ runner.os }}-build-
# ${{ runner.os }}-
# - name: Cache composer cache
# uses: actions/cache@v2
# env:
# cache-name: cache-composer-cache
# with:
# path: ~/.composer/cache
# key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/composer.lock') }}
# restore-keys: |
# ${{ runner.os }}-build-${{ env.cache-name }}-
# ${{ runner.os }}-build-
# ${{ runner.os }}-
# - name: Cache vendor folder
# uses: actions/cache@v2
# env:
# cache-name: cache-vendor
# with:
# path: ./vendor
# key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/composer.lock') }}
# - name: Cache web folder
# uses: actions/cache@v2
# env:
# cache-name: cache-web
# with:
# path: ./web
# key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ github.run_number }}
# - name: Cache drush folder
# uses: actions/cache@v2
# env:
# cache-name: cache-drush
# with:
# path: ./drush
# key: ${{ runner.os }}-build-${{ env.cache-name }}
# - name: prepare-environment-vars
# run: |
# source $BASH_ENV
# - name: visual regression test
# run: ./.ci/test/visual-regression/run
# - name: Upload artifacts
# if: ${{ always() }}
# uses: actions/upload-artifact@v2
# with:
# name: vrt-report
# path: /tmp/artifacts