-
-
Notifications
You must be signed in to change notification settings - Fork 55
159 lines (155 loc) · 6.44 KB
/
test-template.yml
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
158
159
name: test
on:
pull_request: { types: [opened, reopened, synchronize, ready_for_review] }
push: { branches: [main] }
workflow_call:
outputs:
cache_key:
value: ${{ jobs.cache-toolbox.outputs.cache_key }}
env:
SWIFT_IMAGE: 'swift:6.0-jammy'
jobs:
# Check if a build of most recent release of the toolbox for the runner's OS and arch is cached, build and cache it if not
# Run for both PRs and pushes to main so every individual PR doesn't have to rebuild the toolbox at least once
# Use a concurrency group with no cancellation to avoid redundant builds; queued jobs will see the cache when they get their turn
cache-toolbox:
if: ${{ !(github.event.pull_request.draft || false) }}
concurrency:
group: cache_toolbox_for_template
cancel-in-progress: false
outputs:
cache_key: ${{ env.SWIFT_IMAGE }}-vapor-toolbox-${{ steps.latest.outputs.tag }}
runs-on: ubuntu-latest
steps:
- name: Get latest toolbox release
id: latest
run: 'echo "tag=$(curl -fsSL "https://api.github.com/repos/vapor/toolbox/releases/latest" | jq -r .tag_name)" >>"${GITHUB_OUTPUT}"'
- name: Check cache
id: check
uses: actions/cache@v4
with:
key: ${{ env.SWIFT_IMAGE }}-vapor-toolbox-${{ steps.latest.outputs.tag }}
path: toolbox
lookup-only: true
- name: Check out latest toolbox
if: ${{ !steps.check.outputs.cache-hit }}
uses: actions/checkout@v4
with:
repository: vapor/toolbox
ref: ${{ steps.latest.outputs.tag }}
- name: Build and cache toolbox
if: ${{ !steps.check.outputs.cache-hit }}
run: |
docker run --rm -v "$(pwd):/toolbox-build" -w /toolbox-build "${SWIFT_IMAGE}" bash -c \
'swift build -c release --static-swift-stdlib --product vapor && mkdir toolbox && cp .build/release/vapor toolbox/vapor'
# Run vapor new and test the template for all combinations of options
# Only run for PRs, running on push to main would be redundant.
# Use normal "only one of this workflow per branch at a time, cancel stale jobs" concurrency
test-new-and-build:
if: ${{ github.event_name == 'pull_request' && !github.event.pull_request.draft }}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ toJSON(matrix) }}
cancel-in-progress: true
strategy:
fail-fast: false
matrix:
swift-image:
- 'swift:6.0-jammy'
fluentflags:
- '--no-fluent'
#- '--fluent.db mysql' # The MySQL image can't be configured usably via GH Actions at this time
- '--fluent.db postgres'
- '--fluent.db sqlite'
- '--fluent.db mongo'
leafflags:
- '--leaf'
- '--no-leaf'
include:
#- fluentflags: '--fluent.db mysql'
# dbhostname: mysql
- fluentflags: '--fluent.db postgres'
dbhostname: psql
- fluentflags: '--fluent.db mongo'
dbhosturl: 'mongodb://mongo:27017/vapor_database'
runs-on: ubuntu-latest
container: ${{ matrix.swift-image }}
needs: cache-toolbox
services:
mongo: { image: 'mongo:latest' }
#mysql:
# image: mysql:latest
# env: { MYSQL_ALLOW_EMPTY_PASSWORD: 'true', MYSQL_USER: vapor_username, MYSQL_PASSWORD: vapor_password, MYSQL_DATABASE: vapor_database }
psql:
image: postgres:latest
env: { POSTGRES_USER: vapor_username, POSTGRES_DB: vapor_database, POSTGRES_PASSWORD: vapor_password,
POSTGRES_HOST_AUTH_METHOD: 'scram-sha-256', POSTGRES_INITDB_ARGS: '--auth-host=scram-sha-256' }
steps:
- name: Get cached toolbox
id: get-cache
uses: actions/cache/restore@v4
with:
key: ${{ needs.cache-toolbox.outputs.cache_key }}
path: toolbox
fail-on-cache-miss: false
- name: Build toolbox inside container if cache fails
if: ${{ steps.get-cache.cache_hit != 'true' }}
run: |
apt-get update && apt-get install -y curl jq
tag="$(curl -fsSL "https://api.github.com/repos/vapor/toolbox/releases/latest" | jq -r .tag_name)"
git clone https://github.com/vapor/toolbox.git -b "${tag}" toolbox
swift build --package-path toolbox -c debug --product vapor
cp toolbox/.build/debug/vapor toolbox/vapor
- name: Generate a project from the template
env:
HEAD_REF: ${{ github.head_ref }}
CLONE_URL: ${{ github.event.pull_request.head.repo.clone_url }}
run: |
toolbox/vapor new template-test \
--template "${CLONE_URL}" --branch "${HEAD_REF}" \
--no-commit -o template-test \
${{ matrix.fluentflags }} ${{ matrix.leafflags }}
- name: Build and test template
run: swift test --package-path template-test
env:
DATABASE_HOST: ${{ matrix.dbhostname }}
DATABASE_URL: ${{ matrix.dbhosturl }}
# Run vapor new and build the container with Docker Compose for all combinations of options
# Only run for PRs, running on push to main would be redundant.
# Use normal "only one of this workflow per branch at a time, cancel stale jobs" concurrency
test-new-and-container:
if: ${{ github.event_name == 'pull_request' && !github.event.pull_request.draft }}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ toJSON(matrix) }}
cancel-in-progress: true
strategy:
fail-fast: false
matrix:
fluentflags:
- '--no-fluent'
- '--fluent.db mysql'
- '--fluent.db postgres'
- '--fluent.db sqlite'
- '--fluent.db mongo'
leafflags:
- '--leaf'
- '--no-leaf'
needs: cache-toolbox
runs-on: ubuntu-24.04
steps:
- name: Get cached toolbox
uses: actions/cache/restore@v4
with:
key: ${{ needs.cache-toolbox.outputs.cache_key }}
path: toolbox
fail-on-cache-miss: true
- name: Generate a project from the template
env:
HEAD_REF: ${{ github.head_ref }}
CLONE_URL: ${{ github.event.pull_request.head.repo.clone_url }}
run: |
toolbox/vapor new template-test \
--template "${CLONE_URL}" --branch "${HEAD_REF}" \
--no-commit -o template-test \
${{ matrix.fluentflags }} ${{ matrix.leafflags }}
- name: Build Docker container
run: docker compose --project-directory template-test build