The example below shows how to set up a basic pipeline for Deno projects in GitHub Actions:
All this pipeline does at the moment is set up GitHub Actions and Deno, and it
is configured to trigger a workflow run on push and pull request events. Note
that in the example the latest
version of ubuntu
image is used, but you
could specify an exact version for added stability in a production pipeline,
such as ubuntu-20.04
.
To expand the workflow you can add any of the deno
CLI commands that you might
need. The code below shows how to check the formatting, lint the code, run the
tests and generate a test coverage report, all as part of a build
job:
jobs:
build:
runs-on: ubuntu-20.04
steps:
- name: Setup Actions
uses: actions/checkout@v2
- name: Setup Deno
uses: denoland/setup-deno@v1.0.0
with:
deno-version: v1.x
run: deno fmt --check
- name: Analyze code
run: deno lint
- name: Run unit and integration tests
run: deno test -A --coverage=cov --doc
- name: Generate coverage report
run: deno coverage --lcov cov > cov.lcov
- name: Check formatting
This simply checks if the project code is formatted according to Deno’s default formatting conventions.
In this step the deno lint
command checks for syntax and style errors. If
necessary, you can pass a deno.json
configuration file with custom linter
rules.
- name: Run unit and integration tests
run: deno test -A --coverage=cov --doc
Here, Deno runs some tests with a lot of options being passed along! This
example runs with all permissions (-A
) but in reality you may only need a
subset of permissions to run your tests, such as --allow-read
or
--allow-env
. Test coverage is generated with --coverage
into an output
directory and finally, --doc
is provided to typecheck any code blocks in
the project’s documentation.
- name: Generate coverage report
run: deno coverage --lcov cov > cov.lcov
As a Deno module maintainer, you probably want to know that your code works on all of the major operating systems in use today: Linux, MacOS and Windows. A Cross-platform workflow can be achieved by running a matrix of parallel jobs in GitHub Actions, each one running your build on a different operating system:
There can be parts of the pipeline that don’t make sense to run for every OS.
For example, generating the same coverage report on Linux, MacOS and Windows is
a bit redundant. You can use the conditional if
keyword in these cases to
reduce repetition:
- name: Generate coverage report
if: ${{ matrix.os == 'ubuntu-latest' }}
run: deno coverage --lcov cov > cov.lcov
- name: Upload coverage report
if: ${{ matrix.os == 'ubuntu-latest' }}
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}