-
Notifications
You must be signed in to change notification settings - Fork 0
95 lines (81 loc) · 3.21 KB
/
deploy-docs.yml
File metadata and controls
95 lines (81 loc) · 3.21 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
name: Deploy Docs
on:
push:
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
deployments: write
pull-requests: write
issues: write
steps:
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@stable
- uses: actions/cache@v5
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- run: cargo run --bin bough-docs -- build
- run: npm install -g vercel@latest
- name: Deploy to Vercel
id: deploy
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
run: |
DEPLOY_URL=$(vercel deploy target/bough-docs-site --token=$VERCEL_TOKEN --yes --archive=tgz)
echo "deploy_url=$DEPLOY_URL" >> "$GITHUB_OUTPUT"
- name: Compute aliases
id: aliases
run: |
SHORT_SHA=$(git rev-parse --short HEAD)
BRANCH=$(echo "${GITHUB_REF_NAME}" | sed 's/[^a-zA-Z0-9]/-/g' | tr '[:upper:]' '[:lower:]')
ALIASES="${SHORT_SHA}.bough.codeenplace.dev"
ALIASES="${ALIASES},${BRANCH}.bough.codeenplace.dev"
if [[ "$BRANCH" == "main" ]]; then
ALIASES="${ALIASES},bough.codeenplace.dev"
fi
if [[ "$GITHUB_REF" == refs/tags/* ]]; then
TAG=$(echo "${GITHUB_REF_NAME}" | sed 's/[^a-zA-Z0-9]/-/g' | tr '[:upper:]' '[:lower:]')
ALIASES="${ALIASES},${TAG}.bough.codeenplace.dev"
fi
echo "aliases=$ALIASES" >> "$GITHUB_OUTPUT"
echo "Aliases: $ALIASES"
- name: Assign aliases
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
run: |
IFS=',' read -ra ALIAS_LIST <<< "${{ steps.aliases.outputs.aliases }}"
for alias in "${ALIAS_LIST[@]}"; do
echo "Aliasing to $alias"
vercel alias set "${{ steps.deploy.outputs.deploy_url }}" "$alias" --token=$VERCEL_TOKEN --scope=code-en-place
done
- name: Create GitHub deployment
uses: actions/github-script@v8
with:
script: |
const aliases = '${{ steps.aliases.outputs.aliases }}'.split(',');
const isMain = context.ref === 'refs/heads/main';
const deployment = await github.rest.repos.createDeployment({
owner: context.repo.owner,
repo: context.repo.repo,
ref: context.sha,
environment: isMain ? 'production' : 'preview',
auto_merge: false,
required_contexts: [],
transient_environment: !isMain,
production_environment: isMain,
});
await github.rest.repos.createDeploymentStatus({
owner: context.repo.owner,
repo: context.repo.repo,
deployment_id: deployment.data.id,
state: 'success',
environment_url: `https://${aliases[1]}`,
log_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
description: aliases.join(', '),
});