-
Notifications
You must be signed in to change notification settings - Fork 0
82 lines (66 loc) · 2.25 KB
/
deploy-preview.yaml
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
name: deploy api to preview
on:
workflow_dispatch:
inputs:
dry-run:
description: Run the workflow without creating a deployment
required: false
default: false
type: boolean
pull_request:
branches:
- main
types: [opened, synchronize]
# remove default permissions of GITHUB_TOKEN for security
# https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs
permissions: {}
jobs:
deploy:
runs-on: ubuntu-latest
if: github.repository_owner == 'mojisdev'
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false
- name: setup pnpm
uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0
- name: setup node
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
with:
node-version: lts/*
- name: install dependencies
run: pnpm install --frozen-lockfile
- name: build
run: pnpm build
- name: validate openapi
run: pnpm run lint:openapi
- name: lint
run: pnpm run lint
- name: typecheck
run: pnpm run typecheck
- name: test
run: pnpm run test
- name: generate api version
id: api-version
env:
HEAD_REF: ${{ github.head_ref }}
REF_NAME: ${{ github.ref_name }}
run: |
BRANCH_NAME="${HEAD_REF:-$REF_NAME}"
# replace forward slashes and special characters with hyphens
CLEAN_BRANCH=$(echo "$BRANCH_NAME" | sed 's/[^a-zA-Z0-9]/-/g')
# get short SHA (first 7 characters)
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
# combine
echo "version=$CLEAN_BRANCH-$SHORT_SHA" >> "$GITHUB_OUTPUT"
- name: deploy
if: ${{ github.event.inputs.dry-run != 'true' }}
env:
API_VERSION: ${{ steps.api-version.outputs.version }}
uses: cloudflare/wrangler-action@392082e81ffbcb9ebdde27400634aa004b35ea37 # v3.14.0
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
workingDirectory: .
environment: preview
accountId: ${{ secrets.CF_ACCOUNT_ID }}
vars: API_VERSION