Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve GitHub workflows #88

Merged
merged 5 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 23 additions & 77 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,120 +1,66 @@
name: CI
on:
workflow_call:
inputs:
working-directory:
required: false
type: string
default: './'
app-directory:
required: false
type: string
lint-args:
required: false
type: string
default: ''
fmt-args:
required: false
type: string
default: ''
test-args:
required: false
type: string
default: ''
secrets:
CODECOV_TOKEN:
description: Repository codecov token
required: false
jobs:
variables:
name: Get variables
runs-on: ubuntu-latest
outputs:
DENO_DIR: ${{ steps.deno-dir.outputs.DENO_DIR }}
HAS_CODECOV_TOKEN: ${{ steps.secrets.outputs.HAS_CODECOV_TOKEN }}
steps:
- id: deno-dir
name: Get cache directory
run: |
echo "DENO_DIR=${{ runner.temp }}/deno_dir" >> $GITHUB_OUTPUT;
- id: secrets
name: Check secrets
run: |
echo "HAS_CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN != '' }}" >> $GITHUB_OUTPUT;
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v3.3.0
uses: actions/checkout@v4
- name: Setup deno
uses: denoland/setup-deno@main
uses: denoland/setup-deno@v1
with:
deno-version: v1.x
- name: Lint source files
working-directory: ${{ inputs.working-directory }}
run: deno lint ${{ inputs.lint-args }}
run: deno lint
format:
name: Check formatting
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v3.3.0
uses: actions/checkout@v4
- name: Setup deno
uses: denoland/setup-deno@main
uses: denoland/setup-deno@v1
with:
deno-version: v1.x
- name: Check formatting
working-directory: ${{ inputs.working-directory }}
run: deno fmt --check ${{ inputs.fmt-args }}
run: deno fmt --check
test:
name: Test ${{ matrix.os }}
needs: [variables, lint, format]
runs-on: ubuntu-latest
needs: [lint, format]
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
fail-fast: true
env:
APP_ENV: test
DENO_DIR: ${{ needs.variables.outputs.DENO_DIR }}
steps:
- name: Clone repository
uses: actions/checkout@v4
- name: Setup deno
uses: denoland/setup-deno@main
uses: denoland/setup-deno@v1
with:
deno-version: v1.x
- name: Cache Deno dependencies
uses: actions/[email protected]
with:
path: ${{ env.DENO_DIR }}
key: deno-dir-${{ hashFiles('deno.lock') }}
restore-keys: deno-dir-
- name: Build
working-directory: ${{ inputs.app-directory || inputs.working-directory }}
run: deno task build
run: deno task build-dev
- name: Run tests
working-directory: ${{ inputs.working-directory }}
if: |
matrix.os != 'ubuntu-latest'
|| !needs.variables.outputs.HAS_CODECOV_TOKEN
run: deno test ${{ inputs.test-args }} .
if: matrix.os != 'ubuntu-latest'
run: deno task test
- name: Run tests and collect coverage
working-directory: ${{ inputs.working-directory }}
if: |
matrix.os == 'ubuntu-latest'
&& needs.variables.outputs.HAS_CODECOV_TOKEN
run: deno test --coverage=cov ${{ inputs.test-args }} .
if: matrix.os == 'ubuntu-latest'
run: deno task test --coverage
- name: Generate coverage
working-directory: ${{ inputs.working-directory }}
if: |
matrix.os == 'ubuntu-latest'
&& needs.variables.outputs.HAS_CODECOV_TOKEN
run: deno coverage --lcov cov > cov.lcov
if: matrix.os == 'ubuntu-latest'
run: deno coverage --lcov > coverage.lcov
- name: Upload coverage
if: matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v4
with:
files: ${{ inputs.working-directory }}/cov.lcov
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
if: |
matrix.os == 'ubuntu-latest'
&& needs.variables.outputs.HAS_CODECOV_TOKEN
files: coverage.lcov
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
41 changes: 9 additions & 32 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,37 @@ on:
workflow_call:
inputs:
working-directory:
required: false
type: string
default: './'
default: '.'
app-directory:
type: string
default: '.'
entrypoint:
required: false
type: string
default: 'main.ts'
app-directory:
required: false
type: string
project:
required: true
type: string
jobs:
variables:
name: Get variables
runs-on: ubuntu-latest
outputs:
DENO_DIR: ${{ steps.deno_dir.outputs.DENO_DIR }}
steps:
- id: deno_dir
name: Get cache directory
run: |
echo "DENO_DIR=${{ runner.temp }}/deno_dir" >> $GITHUB_OUTPUT
deploy:
name: Deploy
needs: [variables]
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
env:
APP_ENV: production
DENO_DIR: ${{ needs.variables.outputs.DENO_DIR }}
steps:
- name: Clone repository
uses: actions/checkout@v3.3.0
uses: actions/checkout@v4
- name: Setup deno
uses: denoland/setup-deno@main
with:
deno-version: v1.x
- name: Cache Deno dependencies
uses: actions/[email protected]
with:
path: ${{ env.DENO_DIR }}
key: deno-dir-prod-${{ hashFiles('deno.lock') }}
restore-keys: deno-dir-${{ hashFiles('deno.lock') }}
- name: Build
working-directory: ${{ inputs.app-directory }}
run: deno task build
- name: Upload to Deno Deploy
working-directory: ${{ inputs.working-directory }}
run: deno task build-prod
- name: Deploy to Deno Deploy
uses: denoland/deployctl@v1
with:
project: ${{ inputs.project }}
root: ${{ inputs.working-directory }}
entrypoint: '${{ inputs.app-directory || inputs.working-directory }}/${{ inputs.entrypoint }}'
import-map: '${{ inputs.app-directory || inputs.working-directory }}/import_map.json'
entrypoint: '${{ inputs.app-directory }}/${{ inputs.entrypoint }}'
10 changes: 6 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ on:
push:
branches:
- main
workflow_call:
secrets:
CODECOV_TOKEN:
description: Repository codecov token
required: false
jobs:
ci:
name: CI
uses: ./.github/workflows/ci.yml
with:
app-directory: ./example
test-args: '-A'
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
cd:
Expand All @@ -19,4 +21,4 @@ jobs:
uses: ./.github/workflows/deploy.yml
with:
project: udibo-react-app
app-directory: ./example
app-directory: example
24 changes: 0 additions & 24 deletions .github/workflows/release.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# VSCode
.vscode/*.log

# Coverage
coverage

# WIP
test-utils.tsx
2 changes: 1 addition & 1 deletion deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
// Runs the tests.
"test": "export APP_ENV=test NODE_ENV=development && deno test -A --trace-leaks",
// Runs the tests in watch mode.
"test-watch": "export APP_ENV=test NODE_ENV=development && deno test -A --trace-leaks --watch",
"test-watch": "deno task test --watch",
// Checks the formatting and runs the linter.
"check": "deno lint && deno fmt --check",
// Gets your branch up to date with master after a squash merge.
Expand Down
3 changes: 3 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ routes/_main.ts

# VSCode
.vscode/*.log

# Coverage
coverage
2 changes: 1 addition & 1 deletion example/deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// Runs the tests.
"test": "export APP_ENV=test NODE_ENV=development && deno test -A --trace-leaks",
// Runs the tests in watch mode.
"test-watch": "export APP_ENV=test NODE_ENV=development && deno test -A --trace-leaks --watch",
"test-watch": "deno task test --watch",
// Checks the formatting and runs the linter.
"check": "deno lint && deno fmt --check",
// Gets your branch up to date with master after a squash merge.
Expand Down
6 changes: 3 additions & 3 deletions example/routes/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ export default new Router<AppState>()
try {
await next();
} finally {
const dt = Date.now() - start;
response.headers.set("X-Response-Time", `${dt}ms`);
const responseTime = Date.now() - start;
response.headers.set("X-Response-Time", `${responseTime}ms`);
log.info(
`${request.method} ${request.url.href}`,
{ status: response.status, responseTime: dt },
{ status: response.status, responseTime },
);
}
});