-
Notifications
You must be signed in to change notification settings - Fork 0
157 lines (133 loc) · 5.55 KB
/
Copy pathdeploy-production.yml
File metadata and controls
157 lines (133 loc) · 5.55 KB
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
name: deploy-production
on:
repository_dispatch:
types:
- viewer-release
workflow_dispatch:
inputs:
version:
description: Viewer version to deploy (e.g. 3.19.0). Leave empty to deploy current pinned version.
required: false
type: string
permissions:
contents: write
id-token: write
concurrency:
group: viewer-examples-production
cancel-in-progress: false
jobs:
deploy:
runs-on: ubuntu-latest
environment: production
env:
DEPLOY_ENV: prod
steps:
- name: Determine version
id: version
shell: bash
run: |
if [[ "${{ github.event_name }}" == "repository_dispatch" ]]; then
VERSION="${{ github.event.client_payload.version }}"
elif [[ -n "${{ inputs.version }}" ]]; then
VERSION="${{ inputs.version }}"
else
VERSION=""
fi
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
if [[ -n "${VERSION}" ]]; then
echo "Deploying viewer version: ${VERSION}"
else
echo "No version specified - using currently pinned versions."
fi
- name: Create GitHub App token
if: steps.version.outputs.version != ''
id: app-token
uses: actions/create-github-app-token@v3
with:
client-id: "${{ vars.BOT_APP_CLIENT_ID || secrets.BOT_APP_CLIENT_ID }}"
private-key: ${{ secrets.BOT_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: ${{ github.event.repository.name }}
permission-contents: write
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token || github.token }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 24.12.0
cache: npm
- name: Update viewer dependencies
if: steps.version.outputs.version != ''
shell: bash
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
echo "Updating @shapediver/viewer packages to ${VERSION}..."
node <<'NODE'
const fs = require("fs");
const packagePath = "./package.json";
const version = process.env.VERSION;
const pkg = JSON.parse(fs.readFileSync(packagePath, "utf8"));
const deps = pkg.dependencies || {};
const viewerDeps = Object.keys(deps).filter((name) => name.startsWith("@shapediver/viewer"));
if (viewerDeps.length === 0) {
console.log("No @shapediver/viewer dependencies found.");
}
for (const name of viewerDeps) {
console.log(` Setting ${name} -> ${version}`);
deps[name] = version;
}
pkg.dependencies = deps;
fs.writeFileSync(packagePath, `${JSON.stringify(pkg, null, 2)}\n`);
NODE
echo "Updated package.json dependencies."
- name: Install dependencies
run: |
rm -rf node_modules package-lock.json
npm install
- name: Build
run: npm run build
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: us-east-1
- name: Deploy to production
run: npx ts-node ./scripts/deploy.ts
- name: Commit version bump
if: steps.version.outputs.version != ''
shell: bash
run: |
APP_SLUG="${{ steps.app-token.outputs.app-slug }}"
USER_ID="$(gh api "/users/${APP_SLUG}[bot]" --jq .id)"
git config user.name "${APP_SLUG}[bot]"
git config user.email "${USER_ID}+${APP_SLUG}[bot]@users.noreply.github.com"
if [[ -n "$(git status --porcelain)" ]]; then
git add -A
git commit -m "chore(deps): bump viewer packages to ${{ steps.version.outputs.version }}"
git push origin HEAD:development
echo "Pushed version bump to development."
else
echo "No changes to commit."
fi
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
- name: Collect failure artifacts
if: failure()
shell: bash
run: |
rm -rf .github-artifacts/failure
mkdir -p .github-artifacts/failure
if [[ -d dist ]]; then
cp -R dist .github-artifacts/failure/
fi
- name: Upload failure artifacts
if: failure()
uses: actions/upload-artifact@v4
with:
name: viewer-examples-production-failure-artifacts
if-no-files-found: ignore
compression-level: 0
path: .github-artifacts/failure/