Unverified Commit 0e915493 authored by Steven's avatar Steven Committed by GitHub

chore(ci): automatically deploy selected examples (#47130)

fix NEXT-822 ([link](https://linear.app/vercel/issue/NEXT-822))
([NEXT-822](https://linear.app/vercel/issue/NEXT-822))

---------
parent 4c3f59f8
...@@ -952,6 +952,29 @@ jobs: ...@@ -952,6 +952,29 @@ jobs:
- run: ./scripts/publish-native.js - run: ./scripts/publish-native.js
- run: ./scripts/publish-release.js - run: ./scripts/publish-release.js
deployExamples:
name: Deploy examples
runs-on: ubuntu-latest
needs: [publishRelease]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 25
- name: Install Vercel CLI
run: npm i -g vercel@28.16.15
- name: Deploy preview examples
if: ${{ needs.build.outputs.isRelease != 'true' }}
run: ./scripts/deploy-examples.sh
env:
VERCEL_API_TOKEN: ${{ secrets.VERCEL_API_TOKEN }}
DEPLOY_ENVIRONMENT: preview
- name: Deploy production examples
if: ${{ needs.build.outputs.isRelease == 'true' }}
run: ./scripts/deploy-examples.sh
env:
VERCEL_API_TOKEN: ${{ secrets.VERCEL_API_TOKEN }}
DEPLOY_ENVIRONMENT: production
testDeployE2E: testDeployE2E:
name: E2E (deploy) name: E2E (deploy)
runs-on: ubuntu-latest runs-on: ubuntu-latest
......
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
"react-dom": "^18.2.0" "react-dom": "^18.2.0"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "18.7.14", "@types/node": "18.15.3",
"@types/react": "16.9.17", "@types/react": "18.0.28",
"typescript": "4.8.2" "typescript": "4.9.5"
} }
} }
#!/usr/bin/env bash
set -euo pipefail
CHANGED_EXAMPLES=$(node scripts/run-for-change.js --type deploy-examples --listChangedDirectories)
PROD=""
if [ "$DEPLOY_ENVIRONMENT" = "production" ]; then
PROD="--prod"
fi
for CWD in $CHANGED_EXAMPLES ; do
HYPHENS=$(echo "$CWD" | tr '/' '-')
PROJECT="nextjs-$HYPHENS"
echo "Deploying directory $CWD as $PROJECT to Vercel..."
vercel link --cwd "$CWD" --scope vercel --project "$PROJECT" --token "$VERCEL_API_TOKEN" --yes
vercel deploy --cwd "$CWD" --token "$VERCEL_API_TOKEN" $PROD
done;
...@@ -34,6 +34,7 @@ const CHANGE_ITEM_GROUPS = { ...@@ -34,6 +34,7 @@ const CHANGE_ITEM_GROUPS = {
'packages/font/README.md', 'packages/font/README.md',
'packages/next-env/README.md', 'packages/next-env/README.md',
], ],
'deploy-examples': ['examples/image-component'],
cna: ['packages/create-next-app', 'test/integration/create-next-app'], cna: ['packages/create-next-app', 'test/integration/create-next-app'],
'next-codemod': ['packages/next-codemod'], 'next-codemod': ['packages/next-codemod'],
'next-swc': [ 'next-swc': [
...@@ -94,15 +95,20 @@ async function main() { ...@@ -94,15 +95,20 @@ async function main() {
) )
} }
const execArgIndex = process.argv.indexOf('--exec') const execArgIndex = process.argv.indexOf('--exec')
const listChangedDirectories = process.argv.includes(
'--listChangedDirectories'
)
if (execArgIndex < 0) { if (execArgIndex < 0 && !listChangedDirectories) {
throw new Error('no "--exec" flag provided') throw new Error(
'Invalid: must provide either "--exec" or "--listChangedDirectories" flag'
)
} }
let hasMatchingChange = false let hasMatchingChange = false
const changeItems = CHANGE_ITEM_GROUPS[type] const changeItems = CHANGE_ITEM_GROUPS[type]
const execArgs = process.argv.slice(execArgIndex + 1) const execArgs = process.argv.slice(execArgIndex + 1)
if (execArgs.length < 1) { if (execArgs.length < 1 && !listChangedDirectories) {
throw new Error('Missing exec arguments after "--exec"') throw new Error('Missing exec arguments after "--exec"')
} }
...@@ -114,6 +120,7 @@ async function main() { ...@@ -114,6 +120,7 @@ async function main() {
) )
} }
let changedFilesCount = 0 let changedFilesCount = 0
let changedDirectories = []
// always run for canary if flag is enabled // always run for canary if flag is enabled
if (alwaysCanary && branchName === 'canary') { if (alwaysCanary && branchName === 'canary') {
...@@ -130,7 +137,13 @@ async function main() { ...@@ -130,7 +137,13 @@ async function main() {
// if --not flag is provided we execute for any file changed // if --not flag is provided we execute for any file changed
// not included in the change items otherwise we only execute // not included in the change items otherwise we only execute
// if a change item is changed // if a change item is changed
const matchesItem = changeItems.some((item) => file.startsWith(item)) const matchesItem = changeItems.some((item) => {
const found = file.startsWith(item)
if (found) {
changedDirectories.push(item)
}
return found
})
if (!matchesItem && isNegated) { if (!matchesItem && isNegated) {
hasMatchingChange = true hasMatchingChange = true
...@@ -151,6 +164,10 @@ async function main() { ...@@ -151,6 +164,10 @@ async function main() {
} }
if (hasMatchingChange) { if (hasMatchingChange) {
if (listChangedDirectories) {
console.log(changedDirectories.join('\n'))
return
}
const cmd = spawn(execArgs[0], execArgs.slice(1)) const cmd = spawn(execArgs[0], execArgs.slice(1))
cmd.stdout.pipe(process.stdout) cmd.stdout.pipe(process.stdout)
cmd.stderr.pipe(process.stderr) cmd.stderr.pipe(process.stderr)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment