Skip to content

Commit 98c58c6

Browse files
authored
Update deploy-to-pantheon.yml
1 parent 2f52b6c commit 98c58c6

File tree

1 file changed

+58
-19
lines changed

1 file changed

+58
-19
lines changed

.github/workflows/deploy-to-pantheon.yml

Lines changed: 58 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
name: deploy-to-pantheon
22

33
permissions:
4-
contents: read
5-
4+
deployments: write
5+
contents: write
6+
pull-requests: read
7+
68
on:
79
push:
810
branches:
911
- main
12+
paths-ignore:
13+
- .github/**
1014

1115
jobs:
1216
build-and-deploy-to-pantheon:
@@ -37,9 +41,19 @@ jobs:
3741
with:
3842
php-version: "8.2"
3943
- name: Install Terminus
40-
uses: pantheon-systems/terminus-github-actions@v1
41-
with:
42-
pantheon-machine-token: ${{ secrets.PANTHEON_MACHINE_TOKEN }}
44+
run: |
45+
sudo apt update
46+
sudo apt install -y curl php-common php-cli php-xml php-mbstring php-curl git jq
47+
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
48+
php -r "if (hash_file('sha384', 'composer-setup.php') === file_get_contents('https://composer.github.io/installer.sig')) { echo 'Installer verified'.PHP_EOL; } else { echo 'Installer corrupt'.PHP_EOL; unlink('composer-setup.php'); exit(1); }"
49+
php composer-setup.php
50+
php -r "unlink('composer-setup.php');"
51+
mv composer.phar /usr/local/bin/composer
52+
export ASSET_ID="$(curl -sL -H 'Accept: application/vnd.github+json' -H 'X-GitHub-Api-Version: 2022-11-28' https://api.github.com/repos/vfalconisumo/sumo-terminus/releases | jq -r '.[0].assets[0].id')"
53+
curl -sL -H "Accept: application/octet-stream" -H "X-GitHub-Api-Version: 2022-11-28" -o terminus "https://api.github.com/repos/vfalconisumo/sumo-terminus/releases/assets/$ASSET_ID"
54+
chmod +x terminus
55+
mv terminus /usr/local/bin/terminus
56+
terminus self:update
4357
- name: Set up Node.js
4458
uses: actions/setup-node@v3
4559
with:
@@ -53,19 +67,44 @@ jobs:
5367
- name: Install dependencies
5468
run: yarn install --frozen-lockfile
5569
- name: Build the Docusaurus site
56-
run: yarn build
70+
run: |
71+
yarn build
5772
- name: Pantheon, check environment and deploy helpdocs
5873
run: |
59-
# Check for helpdocs environment in Pantheon, create one if not found
60-
PANTHEON_ENV_LIST="$(terminus env:list "${{ vars.PANTHEON_SITE_ID }}" --format=list | xargs)"
61-
DEV_SITE_EXISTS="$(echo "$PANTHEON_ENV_LIST" | grep "helpdocs" | wc -l | xargs)"
62-
if [ "$DEV_SITE_EXISTS" -eq "0" ]; then
63-
terminus multidev:create --no-interaction --no-ansi ${{ vars.PANTHEON_SITE_ID }}.dev helpdocs
64-
terminus lock:enable ${{ vars.PANTHEON_SITE_ID }}.helpdocs -- "${{ secrets.PANTHEON_AUTH_USER }}" "${{ secrets.PANTHEON_AUTH_PASSWORD }}"
65-
fi
66-
# Put environment in SFTP mode, because we're using rsync to move files up
67-
terminus connection:set ${{ vars.PANTHEON_SITE_ID }}.helpdocs sftp
68-
terminus self:plugin:install terminus-rsync-plugin
69-
mv ./build ./help
70-
terminus rsync ./help ${{ vars.PANTHEON_SITE_ID }}.helpdocs:code
71-
terminus env:commit --message "Production build of helpdocs" --force -- ${{ vars.PANTHEON_SITE_ID }}.helpdocs
74+
git config -l | grep 'http\..*\.extraheader' | cut -d= -f1 | xargs -L1 git config --unset-all
75+
git config --global user.email "${{ secrets.PANTHEON_USER_EMAIL }}"
76+
git config --global user.name "GitHub workflow"
77+
terminus auth:login --machine-token ${{ secrets.PANTHEON_MACHINE_TOKEN }}
78+
terminus local:clone --yes ${{ vars.PANTHEON_SITE_ID }}
79+
rsync --archive ./build/ "$HOME/pantheon-local-copies/${{ vars.PANTHEON_SITE_ID }}/help/"
80+
terminus local:commitAndPush --yes sumo-logic-sandbox
81+
terminus workflow:wait --max=600 ${{ vars.PANTHEON_SITE_ID }}.dev
82+
terminus auth:logout
83+
- name: Get runner IP
84+
if: always()
85+
id: ip
86+
uses: haythem/[email protected]
87+
- name: Set env vars
88+
if: always()
89+
run: |
90+
echo "AWS_REGION=us-east-1" >> $GITHUB_ENV
91+
echo "AWS_SG_NAME=webops-sg-jenkins" >> $GITHUB_ENV
92+
- name: Add runner to AWS security group ingress
93+
env:
94+
AWS_ACCESS_KEY_ID: ${{ secrets.WEBOPS_AWS_ACCESS_KEY }}
95+
AWS_SECRET_ACCESS_KEY: ${{ secrets.WEBOPS_AWS_SECRET_KEY }}
96+
AWS_DEFAULT_REGION: ${{ env.AWS_REGION }}
97+
run: aws ec2 authorize-security-group-ingress --group-name ${{ env.AWS_SG_NAME }} --protocol tcp --port ${{ secrets.WEBOPS_JENKINS_PORT || '80' }} --cidr ${{ steps.ip.outputs.ipv4 }}/32
98+
- name: Trigger Jenkins pipeline
99+
run: |
100+
curl -H 'Content-Type: application/json' \
101+
-d '{ "TRIGGER_SOURCE": "${{ github.event_name }} on ${{ github.ref_name }} in ${{ github.repository }}" }' \
102+
-X POST \
103+
${{ secrets.WEBOPS_JENKINS_HOST }}:${{ secrets.WEBOPS_JENKINS_PORT || '80' }}/generic-webhook-trigger/invoke?token=${{ secrets.WEBOPS_WEBHOOK_TOKEN }}
104+
- name: Remove runner from AWS security group ingress
105+
env:
106+
AWS_ACCESS_KEY_ID: ${{ secrets.WEBOPS_AWS_ACCESS_KEY }}
107+
AWS_SECRET_ACCESS_KEY: ${{ secrets.WEBOPS_AWS_SECRET_KEY }}
108+
AWS_DEFAULT_REGION: ${{ env.AWS_REGION }}
109+
if: always()
110+
run: aws ec2 revoke-security-group-ingress --group-name ${{ env.AWS_SG_NAME }} --protocol tcp --port ${{ secrets.WEBOPS_JENKINS_PORT || '80' }} --cidr ${{ steps.ip.outputs.ipv4 }}/32

0 commit comments

Comments
 (0)