Skip to content

Add initial Vapor 5 template #361

Add initial Vapor 5 template

Add initial Vapor 5 template #361

Workflow file for this run

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: 'swiftlang/swift:nightly-6.4.x-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:
- 'swiftlang/swift:nightly-6.4.x-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