-
-
Notifications
You must be signed in to change notification settings - Fork 57
162 lines (158 loc) · 6.34 KB
/
Copy pathtest-template.yml
File metadata and controls
162 lines (158 loc) · 6.34 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
name: test
on:
pull_request: { types: [opened, reopened, synchronize, ready_for_review] }
push: { branches: [main] }
workflow_call:
inputs:
is_called:
required: false
type: string
default: "yes"
outputs:
cache-key:
value: ${{ jobs.cache-toolbox.outputs.cache-key }}
permissions:
contents: read
env:
SWIFT_IMAGE: 'swift:6.3-noble'
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: ${{ steps.latest.outputs.cache-key }}
runs-on: ubuntu-latest
steps:
- name: Get latest toolbox release
id: latest
run: |
tag="$(curl -fsSL 'https://api.github.com/repos/vapor/toolbox/releases/latest' | jq -r '.tag_name')"
echo "tag=${tag}" >>"${GITHUB_OUTPUT}"
echo "cache-key=${SWIFT_IMAGE}-vapor-toolbox-${tag}" >>"${GITHUB_OUTPUT}"
- name: Check cache
id: check
uses: actions/cache@v6
with:
key: ${{ steps.latest.outputs.cache-key }}
path: toolbox
lookup-only: true
- name: Check out latest toolbox
if: ${{ !steps.check.outputs.cache-hit }}
uses: actions/checkout@v7
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
# Use normal "only one of this workflow per branch at a time, cancel stale jobs" concurrency
test-new-and-build:
if: ${{ inputs.is_called != 'yes' && !(github.event.pull_request.draft || false) }}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-test-new-and-build-${{ toJSON(matrix) }}
cancel-in-progress: true
strategy:
fail-fast: false
matrix:
swift-image:
- 'swift:6.3-noble'
fluentflags:
- '--no-fluent'
- '--fluent.db mysql'
- '--fluent.db postgres'
- '--fluent.db sqlite'
leafflags:
- '--leaf'
- '--no-leaf'
include:
- fluentflags: '--fluent.db mysql'
dbhostname: mysql
- fluentflags: '--fluent.db postgres'
dbhostname: psql
runs-on: ubuntu-latest
container:
image: ${{ matrix.swift-image }}
volumes: [ 'mysqlshare:/mysql' ]
needs: cache-toolbox
services:
mysql:
image: mysql:latest
volumes: [ 'mysqlshare:/var/run/mysqld' ]
env: { MYSQL_USER: vapor_username, MYSQL_PASSWORD: vapor_password, MYSQL_DATABASE: vapor_database, MYSQL_ALLOW_EMPTY_PASSWORD: true }
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: Install zstd for cache action
run: apt-get update && apt-get install -y zstd
- name: Get cached toolbox
id: get-cache
uses: actions/cache/restore@v6
with:
key: ${{ needs.cache-toolbox.outputs.cache-key }}
path: toolbox
fail-on-cache-miss: true
- name: Fix MySQL config when testing MySQL
if: ${{ matrix.fluentflags == '--fluent.db mysql' }}
run: |
apt-get update && apt-get install -y 'mysql-client-core-*'
echo "SET PERSIST ssl_ca='',ssl_cert='',ssl_key='';ALTER INSTANCE RELOAD TLS NO ROLLBACK ON ERROR;" | mysql -BS/mysql/mysqld.sock
- name: Generate a project from the template
env:
HEAD_REF: ${{ github.head_ref || github.ref_name }}
CLONE_URL: ${{ github.event.pull_request.head.repo.clone_url || github.event.repository.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 }}
# Run vapor new and build the container with Docker Compose for all combinations of options
# Use normal "only one of this workflow per branch at a time, cancel stale jobs" concurrency
test-new-and-container:
if: ${{ inputs.is_called != 'yes' && !(github.event.pull_request.draft || false) }}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-test-new-and-container-${{ toJSON(matrix) }}
cancel-in-progress: true
strategy:
fail-fast: false
matrix:
fluentflags:
- '--no-fluent'
- '--fluent.db mysql'
- '--fluent.db postgres'
- '--fluent.db sqlite'
leafflags:
- '--leaf'
- '--no-leaf'
needs: cache-toolbox
runs-on: ubuntu-latest
steps:
- name: Get cached toolbox
uses: actions/cache/restore@v6
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 || github.ref_name }}
CLONE_URL: ${{ github.event.pull_request.head.repo.clone_url || github.event.repository.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