Skip to content

Commit ef85806

Browse files
update Pantheon workflows (#5868)
Signed-off-by: vfalconisumo <[email protected]> Co-authored-by: Kim (Sumo Logic) <[email protected]>
1 parent d031d34 commit ef85806

File tree

7 files changed

+328
-71
lines changed

7 files changed

+328
-71
lines changed

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

Lines changed: 0 additions & 71 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Build helpdocs site
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
workflow_call:
8+
9+
jobs:
10+
build-helpdocs-site:
11+
runs-on: ubuntu-latest
12+
environment:
13+
name: production
14+
url: https://www.sumologic.com/
15+
env:
16+
CI: true
17+
NODE_ENV: production
18+
NODE_OPTIONS: "--max-old-space-size=8192 --max-http-header-size=8192"
19+
HOSTNAME: https://www.sumologic.com
20+
BASE_URL: /help/
21+
steps:
22+
- uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0
25+
- name: Set up Node.js
26+
uses: actions/setup-node@v3
27+
with:
28+
node-version: '20.x'
29+
cache: 'yarn'
30+
- name: Docusaurus Webpack cache
31+
uses: actions/cache@v3
32+
with:
33+
path: node_modules/.cache
34+
key: ${{ runner.os }}-webpack-cache-${{ hashFiles('yarn.lock') }}
35+
- name: Install dependencies
36+
run: yarn install --frozen-lockfile
37+
- name: Build the Docusaurus site
38+
run: |
39+
yarn build
40+
- name: Upload build artifact
41+
uses: actions/upload-artifact@v4
42+
id: artifact-upload-step
43+
with:
44+
name: build-output
45+
path: ./build/

.github/workflows/job_pantheon.yml

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
name: Deploy to Pantheon
2+
3+
permissions:
4+
contents: write
5+
6+
on:
7+
workflow_call:
8+
inputs:
9+
SITE_PATH:
10+
description: Destination filepath, must include trailing slash and no leading slash (default is empty string, or the / site root)
11+
default: ''
12+
type: string
13+
PANTHEON_SITE_ID:
14+
description: Human-readable site ID
15+
type: string
16+
required: true
17+
PANTHEON_STAGING_ENV_NAME:
18+
type: string
19+
default: "env-${{ github.sha }}"
20+
description: Name of the staging environment (11-char max)
21+
PANTHEON_DESTINATION:
22+
description: Target Pantheon environment, either 'dev' or 'staging'
23+
required: true
24+
type: string
25+
secrets:
26+
PANTHEON_SSH_KEY:
27+
required: true
28+
PANTHEON_KNOWN_HOSTS:
29+
required: true
30+
PANTHEON_USER_EMAIL:
31+
required: true
32+
PANTHEON_AUTH_USER:
33+
required: true
34+
PANTHEON_AUTH_PASSWORD:
35+
required: true
36+
PANTHEON_MACHINE_TOKEN:
37+
required: true
38+
39+
jobs:
40+
deploy-to-pantheon:
41+
runs-on: ubuntu-latest
42+
steps:
43+
- uses: actions/checkout@v4
44+
with:
45+
fetch-depth: 0
46+
- name: Install SSH key
47+
uses: shimataro/ssh-key-action@v2
48+
with:
49+
key: ${{ secrets.PANTHEON_SSH_KEY }}
50+
config: |
51+
Host *.drush.in
52+
StrictHostKeyChecking no
53+
known_hosts: ${{ secrets.PANTHEON_KNOWN_HOSTS }}
54+
- name: Setup PHP
55+
uses: shivammathur/setup-php@v2
56+
with:
57+
php-version: "8.2"
58+
- name: Install Terminus
59+
run: |
60+
sudo apt update
61+
sudo apt install -y curl php-common php-cli php-xml php-mbstring php-curl git jq
62+
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
63+
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); }"
64+
php composer-setup.php
65+
php -r "unlink('composer-setup.php');"
66+
mv composer.phar /usr/local/bin/composer
67+
curl -L https://github.com/pantheon-systems/terminus/releases/download/4.0.3/terminus.phar --output terminus
68+
chmod +x terminus
69+
mv terminus /usr/local/bin/terminus
70+
terminus self:update
71+
git config -l | grep 'http\..*\.extraheader' | cut -d= -f1 | xargs -L1 git config --unset-all
72+
git config --global user.email "${{ secrets.PANTHEON_USER_EMAIL }}"
73+
git config --global user.name "GitHub workflow"
74+
echo "PANTHEON_BRANCH=master" >> $GITHUB_ENV
75+
echo "PANTHEON_ENV=dev" >> $GITHUB_ENV
76+
- name: Retrieve build artifact
77+
uses: actions/download-artifact@v5
78+
with:
79+
name: build-output
80+
path: ./build
81+
- name: Terminus login
82+
run: terminus auth:login --machine-token ${{ secrets.PANTHEON_MACHINE_TOKEN }}
83+
- name: Staging environment setup
84+
if: inputs.PANTHEON_DESTINATION == 'staging'
85+
run: |
86+
STAGING_NAME="${{ inputs.PANTHEON_STAGING_ENV_NAME }}"
87+
NORMLIZED_STAGING_ENV_NAME="${STAGING_NAME:0:11}"
88+
DEV_SITE_EXISTS="$(terminus env:list "${{ inputs.PANTHEON_SITE_ID }}" --format=list | grep "$NORMLIZED_STAGING_ENV_NAME" | wc -l | xargs)"
89+
if [ "$DEV_SITE_EXISTS" -eq "0" ]; then
90+
terminus multidev:create --no-interaction --no-ansi ${{ inputs.PANTHEON_SITE_ID }}.dev "$NORMLIZED_STAGING_ENV_NAME"
91+
terminus lock:enable ${{ inputs.PANTHEON_SITE_ID }}.$NORMLIZED_STAGING_ENV_NAME -- "${{ secrets.PANTHEON_AUTH_USER }}" "${{ secrets.PANTHEON_AUTH_PASSWORD }}"
92+
fi
93+
terminus connection:set "${{ inputs.PANTHEON_SITE_ID }}.$NORMLIZED_STAGING_ENV_NAME" git
94+
echo "PANTHEON_ENV=helpdocs" >> $GITHUB_ENV
95+
echo "PANTHEON_BRANCH=$NORMLIZED_STAGING_ENV_NAME" >> $GITHUB_ENV
96+
- name: Commit build and deploy to Pantheon repo
97+
run: |
98+
terminus local:clone --yes --branch="${{ env.PANTHEON_BRANCH }}" ${{ inputs.PANTHEON_SITE_ID }}
99+
rsync --archive ./build/ "$HOME/pantheon-local-copies/${{ inputs.PANTHEON_SITE_ID }}/${{ inputs.SITE_PATH }}"
100+
chmod -R 755 $HOME/pantheon-local-copies/${{ inputs.PANTHEON_SITE_ID }}/${{ inputs.SITE_PATH }}
101+
git -C "$HOME/pantheon-local-copies/${{ inputs.PANTHEON_SITE_ID }}" add .
102+
git -C "$HOME/pantheon-local-copies/${{ inputs.PANTHEON_SITE_ID }}" commit -m "Added content from ${{ github.repository }} at ${{ github.sha }}"
103+
WATCH_COMMIT=$(git -C "$HOME/pantheon-local-copies/${{ inputs.PANTHEON_SITE_ID }}" rev-parse --verify HEAD)
104+
git -C "$HOME/pantheon-local-copies/${{ inputs.PANTHEON_SITE_ID }}" push origin
105+
terminus workflow:wait --max 600 --commit $WATCH_COMMIT -- ${{ inputs.PANTHEON_SITE_ID }}.${{ env.PANTHEON_ENV }}
106+
- name: Terminus logout
107+
if: always()
108+
run: |
109+
rm -rf $HOME/pantheon-local-copies/${{ inputs.PANTHEON_SITE_ID }}/${{ inputs.SITE_PATH }}
110+
terminus auth:logout
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Slack notification
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
SLACK_MESSAGE:
7+
type: string
8+
required: true
9+
secrets:
10+
SLACK_URL:
11+
required: true
12+
13+
jobs:
14+
notify-channel:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: slackapi/slack-github-action@91efab103c0de0a537f72a35f6b8cda0ee76bf0a
18+
with:
19+
webhook: ${{ secrets.SLACK_URL }}
20+
webhook-type: incoming-webhook
21+
payload: |
22+
blocks:
23+
- type: "section"
24+
text:
25+
type: "mrkdwn"
26+
text: "${{ inputs.SLACK_MESSAGE }}"
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Trigger Jenkins pipeline
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
JENKINS_TRIGGER_SOURCE:
7+
default: "${{ github.event_name }} on ${{ github.ref_name }} in ${{ github.repository }} at ${{ github.sha }}"
8+
type: string
9+
secrets:
10+
WEBOPS_AWS_REGION:
11+
required: true
12+
WEBOPS_AWS_SG_NAME:
13+
required: true
14+
WEBOPS_JENKINS_PORT:
15+
required: true
16+
WEBOPS_JENKINS_HOST:
17+
required: true
18+
WEBOPS_AWS_ACCESS_KEY:
19+
required: true
20+
WEBOPS_AWS_SECRET_KEY:
21+
required: true
22+
WEBOPS_WEBHOOK_TOKEN:
23+
required: true
24+
25+
jobs:
26+
trigger-jenkins-pipeline:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- name: Get runner IP
30+
if: always()
31+
id: ip
32+
uses: haythem/[email protected]
33+
- name: Add runner to AWS security group ingress
34+
env:
35+
AWS_ACCESS_KEY_ID: ${{ secrets.WEBOPS_AWS_ACCESS_KEY }}
36+
AWS_SECRET_ACCESS_KEY: ${{ secrets.WEBOPS_AWS_SECRET_KEY }}
37+
AWS_DEFAULT_REGION: ${{ secrets.WEBOPS_AWS_REGION }}
38+
run: aws ec2 authorize-security-group-ingress --group-name ${{ secrets.WEBOPS_AWS_SG_NAME }} --protocol tcp --port ${{ secrets.WEBOPS_JENKINS_PORT }} --cidr ${{ steps.ip.outputs.ipv4 }}/32
39+
- name: Trigger Jenkins pipeline
40+
run: |
41+
curl -H 'Content-Type: application/json' \
42+
-d '{ "TRIGGER_SOURCE": "${{ inputs.JENKINS_TRIGGER_SOURCE }}" }' \
43+
-X POST \
44+
${{ secrets.WEBOPS_JENKINS_HOST }}:${{ secrets.WEBOPS_JENKINS_PORT || '80' }}/generic-webhook-trigger/invoke?token=${{ secrets.WEBOPS_WEBHOOK_TOKEN }}
45+
- name: Remove runner from AWS security group ingress
46+
env:
47+
AWS_ACCESS_KEY_ID: ${{ secrets.WEBOPS_AWS_ACCESS_KEY }}
48+
AWS_SECRET_ACCESS_KEY: ${{ secrets.WEBOPS_AWS_SECRET_KEY }}
49+
AWS_DEFAULT_REGION: ${{ secrets.WEBOPS_AWS_REGION }}
50+
if: always()
51+
run: aws ec2 revoke-security-group-ingress --group-name ${{ secrets.WEBOPS_AWS_SG_NAME }} --protocol tcp --port ${{ secrets.WEBOPS_JENKINS_PORT }} --cidr ${{ steps.ip.outputs.ipv4 }}/32
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Deploy to production
2+
3+
permissions:
4+
contents: write
5+
6+
on:
7+
workflow_dispatch:
8+
push:
9+
branches:
10+
- main
11+
paths-ignore:
12+
- .github/**
13+
14+
jobs:
15+
build-site:
16+
uses: ./.github/workflows/job_build-site.yml
17+
deploy-to-pantheon:
18+
needs: build-site
19+
uses: ./.github/workflows/job_pantheon.yml
20+
with:
21+
PANTHEON_DESTINATION: dev
22+
SITE_PATH: help/
23+
PANTHEON_SITE_ID: ${{ vars.PANTHEON_SITE_ID }}
24+
secrets:
25+
PANTHEON_AUTH_PASSWORD: ${{ secrets.PANTHEON_AUTH_PASSWORD }}
26+
PANTHEON_AUTH_USER: ${{ secrets.PANTHEON_AUTH_USER }}
27+
PANTHEON_KNOWN_HOSTS: ${{ secrets.PANTHEON_KNOWN_HOSTS }}
28+
PANTHEON_MACHINE_TOKEN: ${{ secrets.PANTHEON_MACHINE_TOKEN }}
29+
PANTHEON_SSH_KEY: ${{ secrets.PANTHEON_SSH_KEY }}
30+
PANTHEON_USER_EMAIL: ${{ secrets.PANTHEON_USER_EMAIL }}
31+
trigger-jenkins-pipeline:
32+
needs: deploy-to-pantheon
33+
uses: ./.github/workflows/job_trigger-jenkins-pipeline.yml
34+
secrets:
35+
WEBOPS_AWS_REGION: ${{ secrets.WEBOPS_AWS_REGION }}
36+
WEBOPS_AWS_SG_NAME: ${{ secrets.WEBOPS_AWS_SG_NAME }}
37+
WEBOPS_JENKINS_PORT: ${{ secrets.WEBOPS_JENKINS_PORT }}
38+
WEBOPS_JENKINS_HOST: ${{ secrets.WEBOPS_JENKINS_HOST }}
39+
WEBOPS_AWS_ACCESS_KEY: ${{ secrets.WEBOPS_AWS_ACCESS_KEY }}
40+
WEBOPS_AWS_SECRET_KEY: ${{ secrets.WEBOPS_AWS_SECRET_KEY }}
41+
WEBOPS_WEBHOOK_TOKEN: ${{ secrets.WEBOPS_WEBHOOK_TOKEN }}
42+
notify-channel:
43+
needs: [build-site,deploy-to-pantheon,trigger-jenkins-pipeline]
44+
if: ${{ failure() }}
45+
uses: ./.github/workflows/job_slack-notification.yml
46+
with:
47+
SLACK_MESSAGE: ":red_circle: helpdocs workflow failed [<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|details>]"
48+
secrets:
49+
SLACK_URL: ${{ secrets.WEBOPS_SLACK_URL }}

0 commit comments

Comments
 (0)