-
Notifications
You must be signed in to change notification settings - Fork 0
169 lines (142 loc) · 5.34 KB
/
deploy-dev.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
name: "Deploy to Dev"
on:
pull_request:
push:
branches:
- uswds-redesign
jobs:
deploy-dev:
runs-on: self-hosted
if: ${{ !startsWith(github.actor, 'bot-') }}
steps:
# Step 1: Checkout the repo
- name: Checkout
uses: actions/checkout@v4
- name: Install project dependencies
run: |
sudo dnf -y install ruby3.2 ruby3.2-devel openssl-devel amazon-rpm-config gcc-c++
# Step 2: Set base url/deployment path
- name: Set Deployment Path
id: set_deploy_path
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "DEPLOY_PATH=${{ github.event.number }}" >> $GITHUB_ENV
else
echo "DEPLOY_PATH=${{ github.ref_name }}" >> $GITHUB_ENV
fi
# Step 3: Set up Node.js
- name: Set up Node.js
uses: actions/setup-node@v4
with:
cache: 'npm'
node-version-file: '.nvmrc'
# node-version: 20 ## Using a .nvmrc file to stay in sync with the repo
# Step 4: Set up Ruby
- name: Set up ruby
run: |
ruby -v
echo 'export GEM_HOME="$HOME/gems"' >> $GITHUB_ENV
echo 'export PATH="$HOME/ec2-user/bin:$HOME/gems/bin:$PATH"' >> $GITHUB_ENV
# Step 5: Install Ruby Gems
- name: Install jekyll and bundler
run: |
sudo chmod -R 777 /usr/share
sudo gem install jekyll bundler
sudo bundle install
# Step 6: Install Node.js Dependencies
- name: Install npm dependencies
run: |
npm ci
# Step 7: Compile Assets
- name: Compile assets with Gulp
run: |
npm run assets:build
# Step 8: Build Site
- name: Build the site
env:
JEKYLL_ENV: production
run: |
bundle exec jekyll build --baseurl /${{ env.DEPLOY_PATH }}
# Step 9: Initialize AWS Connection
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ vars.AWS_REGION }}
role-to-assume: arn:aws:iam::${{ secrets.TEST_ACCOUNT_ID }}:role/delegatedadmin/developer/ab2d-test-github-actions
# Step 10: Deploy to S3
- name: Deploy the site
run: |
aws s3 sync _site/ s3://website-ab2d-east-impl/${{ env.DEPLOY_PATH }}/
comment-pr:
needs: deploy-dev
runs-on: self-hosted
if: github.event_name == 'pull_request'
permissions:
pull-requests: 'write'
steps:
- name: Post or update comment
uses: actions/github-script@v7
with:
script: |
const commentIdentifier = '## Deploy Preview';
const commitSha = context.payload.pull_request.head.sha;
const commitUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/commit/${commitSha}`;
const previewUrl = `https://dyx9tyg1h7v8p.cloudfront.net/${context.issue.number}/`
const body = `${commentIdentifier}
**Preview URL:** [${previewUrl}](${previewUrl})
**Latest commit:** [${commitSha.substring(0, 7)}](\`${commitUrl}\`)`;
async function findComment(issueNumber) {
if (!issueNumber) return null;
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
});
return comments.data.find((comment) =>
comment.body.startsWith(commentIdentifier)
);
}
async function createOrUpdateComment(issueNumber) {
if (!issueNumber) {
console.log('No issue number provided. Cannot post or update comment.');
return;
}
const existingComment = await findComment(issueNumber);
if (existingComment) {
await github.rest.issues.deleteComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
});
}
await github.rest.issues.createComment({
issue_number: issueNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body: body,
});
}
if (context.eventName === 'pull_request') {
if (context.issue.number) {
await createOrUpdateComment(context.issue.number);
}
} else if (context.eventName === 'push') {
const pullRequests = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
head: `${context.repo.owner}:${context.ref.replace('refs/heads/','')}`,
});
if (pullRequests.data.length > 0) {
await createOrUpdateComment(pullRequests.data[0].number);
} else {
console.log(
'No open pull request found for this push.'
);
}
}
a11y-check:
needs: deploy-dev
uses: ./.github/workflows/a11y-check.yml
# broken-link-check:
# uses: ./.github/workflows/broken-link-check.yml