Repository navigation
139 lines (124 loc) · 4.7 KB
/
Copy pathdeploy-preview.yaml
File metadata and controls
139 lines (124 loc) · 4.7 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
name: Deploy Preview
on:
pull_request:
types: [opened, synchronize, reopened]
branches:
- main
paths:
- 'packages/website/**'
- 'docs/**'
- '*.md'
- 'README.md'
- 'packages/base/src/**/*.css'
- 'packages/base/src/**/*.ts'
- 'packages/ai/src/**/*.css'
- 'packages/ai/src/**/*.ts'
- 'packages/ai/src/**/*.tsx'
- 'packages/compat/src/**/*.css'
- 'packages/compat/src/**/*.ts'
- 'packages/compat/src/**/*.tsx'
- 'packages/fiori/src/**/*.css'
- 'packages/fiori/src/**/*.ts'
- 'packages/fiori/src/**/*.tsx'
- 'packages/main/src/**/*.css'
- 'packages/main/src/**/*.ts'
- 'packages/main/src/**/*.tsx'
- '!**/*.spec.ts'
- '!**/*.test.ts'
- '!**/test/**'
permissions:
contents: read
jobs:
deploy-preview:
# Skip for PRs from forks — they don't have access to the Netlify secrets,
# so the deploy step would always fail. A skipped check does not block merge.
if: github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
environment: netlify-preview
steps:
- name: Generate App Token
id: app-token
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
with:
client-id: ${{ secrets.TOKEN_APP_ID }}
private-key: ${{ secrets.TOKEN_APP_KEY }}
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Setup Node.js
uses: actions/setup-node@v4.1.0
with:
node-version: 22
cache: 'yarn'
- name: Install
run: |
export NODE_OPTIONS="--max_old_space_size=4096"
yarn install
- name: Update version.md for PR
run: |
mkdir -p packages/website/static
touch packages/website/static/version.md
echo "PR #${{ github.event.number }} - $(git log -1 --format='%h %s')" > packages/website/static/version.md
echo "Branch: ${{ github.head_ref }}" >> packages/website/static/version.md
echo "Commit: $(git rev-parse HEAD)" >> packages/website/static/version.md
- name: Build
env:
DEPLOYMENT_TYPE: "netlify_preview"
DEPLOYMENT_NETLIFY_PREVIEW_BASE_URL: "https://pr-${{ github.event.number }}--ui5-webcomponents-preview.netlify.app"
PR_NUMBER: "${{ github.event.number }}"
run: |
yarn ci:deploy:preview
- name: Check PR status
id: final-pr-check
if: always()
uses: actions/github-script@v7
with:
github-token: ${{ steps.app-token.outputs.token }}
script: |
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number
});
if (pr.state !== 'open') {
console.log(`PR #${pr.number} was closed during build, skipping deployment`);
const fs = require('fs');
fs.appendFileSync(process.env.GITHUB_OUTPUT, `should_deploy=false\n`);
return;
}
console.log(`PR #${pr.number} is still open, proceeding with deployment`);
const fs = require('fs');
fs.appendFileSync(process.env.GITHUB_OUTPUT, `should_deploy=true\n`);
- name: Config Netlify CORS
if: steps.final-pr-check.outputs.should_deploy == 'true'
run: |
cat > packages/website/build/netlify.toml << 'EOF'
[build]
publish = "."
# CORS headers for local-cdn resources
[[headers]]
for = "/local-cdn/*"
[headers.values]
Access-Control-Allow-Origin = "*"
Access-Control-Allow-Methods = "GET, HEAD, OPTIONS"
Access-Control-Allow-Headers = "Content-Type, Accept"
Access-Control-Max-Age = "86400"
Cache-Control = "public, max-age=31536000, immutable"
EOF
- name: Deploy
if: steps.final-pr-check.outputs.should_deploy == 'true'
uses: nwtgck/actions-netlify@v3.0
with:
publish-dir: './packages/website/build'
production-deploy: false
github-token: ${{ steps.app-token.outputs.token }}
deploy-message: "Deploy preview for PR #${{ github.event.number }}"
alias: pr-${{ github.event.number }}
enable-pull-request-comment: true
enable-commit-comment: false
overwrites-pull-request-comment: true
github-deployment-environment: preview
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}