diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e45eb58..a89f50a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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/cache@v3.2.3 - 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 }} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index af240af..3d1bc99 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -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/cache@v3.2.3 - 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 }}' diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2408263..a220fc4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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: @@ -19,4 +21,4 @@ jobs: uses: ./.github/workflows/deploy.yml with: project: udibo-react-app - app-directory: ./example + app-directory: example diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index f12ff82..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: Release -on: - create: - push: - branches: - - main - workflow_call: -jobs: - release: - name: Release - runs-on: ubuntu-latest - steps: - - name: Get version - if: startsWith(github.ref, 'refs/tags/') - shell: bash - run: | - echo "RELEASE_VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV - - name: Release - if: env.RELEASE_VERSION != '' - uses: softprops/action-gh-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - draft: true diff --git a/.gitignore b/.gitignore index a05e433..3cd37a6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,8 @@ # VSCode .vscode/*.log +# Coverage +coverage + # WIP test-utils.tsx diff --git a/deno.jsonc b/deno.jsonc index d318dd9..506cdf8 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -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. diff --git a/example/.gitignore b/example/.gitignore index 2691850..814bf31 100644 --- a/example/.gitignore +++ b/example/.gitignore @@ -6,3 +6,6 @@ routes/_main.ts # VSCode .vscode/*.log + +# Coverage +coverage diff --git a/example/deno.jsonc b/example/deno.jsonc index 01ae64e..7554d85 100644 --- a/example/deno.jsonc +++ b/example/deno.jsonc @@ -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. diff --git a/example/routes/main.ts b/example/routes/main.ts index ddcefdb..4ab2674 100644 --- a/example/routes/main.ts +++ b/example/routes/main.ts @@ -10,11 +10,11 @@ export default new Router() 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 }, ); } });