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

[PE-253] Add Github Actions #2328

Merged
merged 23 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
48 changes: 48 additions & 0 deletions .github/actions/build-and-test/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
author: airtasker
name: build-and-test
description: Build and test.

inputs:
node_version:
required: true
description: The version of Node.js to use.
shard:
required: true
description: Which shard we're on.

runs:
using: composite
steps:
- uses: ./.github/actions/prepare-repository

- name: Compile the repository on this version of Node.
run: yarn build
shell: bash

- name: Create test reports directory
run: mkdir -p ./test-reports/jest
shell: bash

- name: Find and run test files
run: |
TESTFILES=$(find lib -name '*.spec.ts')
for file in $TESTFILES; do
filename=$(basename "$file" .spec.ts)
JEST_JUNIT_OUTPUT_NAME="${{ github.sha }}_${{ github.run_id }}_node${{ inputs.node_version }}_${{ inputs.shard }}_${filename}_results.xml" \
yarn test $file --ci --reporters=default --reporters=jest-junit --shard=${{ inputs.shard }}
done
env:
JEST_JUNIT_OUTPUT_DIR: ./test-reports/jest
JEST_JUNIT_CLASSNAME: "{filepath}"
JEST_JUNIT_UNIQUE_OUTPUT_NAME: "true"
shell: bash

- name: Build the documentation.
run: |-
set -uex
if [ ${{ inputs.node_version }} -gt 16 ]; then
# Without this, we get `Error: error:0308010C:digital envelope routines::unsupported` on Node >= 17.
export NODE_OPTIONS="--openssl-legacy-provider"
fi
yarn build-docs
shell: bash
47 changes: 47 additions & 0 deletions .github/actions/prepare-repository/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
author: airtasker
name: prepare-repository
description: Prepare the repository for building and testing.

runs:
using: composite

steps:
- uses: actions/checkout@v4
- name: restore_cache
uses: actions/cache@v3
with:
key: v3-dependencies-{{ checksum "yarn.lock" }}
path: node_modules
restore-keys: |-
v3-dependencies-{{ checksum "yarn.lock" }}
v3-dependencies

- name: Install main dependencies
run: yarn install --frozen-lockfile
shell: bash

- name: save_cache
uses: actions/cache@v3
with:
path: node_modules
key: v3-dependencies-{{ checksum "yarn.lock" }}

- name: restore_cache
uses: actions/cache@v3
with:
key: v3-docs-dependencies-{{ checksum "docs/yarn.lock" }}
path: docs/node_modules
restore-keys: |-
v3-docs-dependencies-{{ checksum "docs/yarn.lock" }}
v3-docs-dependencies

- name: Install docs dependencies
run: yarn install --frozen-lockfile
working-directory: docs/
shell: bash

- name: save_cache
uses: actions/cache@v3
with:
path: docs/node_modules
key: v3-docs-dependencies-{{ checksum "docs/yarn.lock" }}
53 changes: 37 additions & 16 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,40 @@
version: 2

updates:
- package-ecosystem: npm
directory: "/"
schedule:
interval: weekly
day: monday
time: "05:00"
timezone: Australia/Sydney
open-pull-requests-limit: 99
- package-ecosystem: npm
directory: "/docs"
schedule:
interval: weekly
day: monday
time: "05:00"
timezone: Australia/Sydney
open-pull-requests-limit: 99
- package-ecosystem: npm
directory: "/"
schedule:
interval: weekly
day: monday
time: "05:00"
timezone: Australia/Sydney
open-pull-requests-limit: 99
- package-ecosystem: npm
directory: "/docs"
schedule:
interval: weekly
day: monday
time: "05:00"
timezone: Australia/Sydney
open-pull-requests-limit: 99
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: daily
time: "09:00"
timezone: Australia/Sydney
open-pull-requests-limit: 10
- package-ecosystem: github-actions
directory: "/.github/actions/build-and-test"
schedule:
interval: daily
time: "09:00"
timezone: Australia/Sydney
open-pull-requests-limit: 10
- package-ecosystem: github-actions
directory: "/.github/actions/prepare-repository"
schedule:
interval: daily
time: "09:00"
timezone: Australia/Sydney
open-pull-requests-limit: 10
83 changes: 83 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: airtasker/spot/build-and-test

on:
pull_request:
branches:
- master
push:
branches:
- master
release:
types: [published]

env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

jobs:
test:
name: test-node-${{ matrix.node-version }}
runs-on: runs-on,runner=4cpu-linux-x64
strategy:
fail-fast: true # if one job fails, stop the rest
matrix:
node-version: [14, 16, 18, 20]
shard:
[
"1",
"2",
"3",
"4",
]
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup NodeJS ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Run tests
uses: "./.github/actions/build-and-test"
with:
node_version: ${{ matrix.node-version }}
shard: ${{ matrix.shard }}

- name: Upload test results
uses: actions/upload-artifact@v4
with:
name: test-results-node-${{ matrix.node-version }}-${{ matrix.shard }}
path: ./test-reports

- name: Test summary
uses: test-summary/action@v2
with:
paths: ./test-reports/**/*.xml

lint-check:
runs-on: runs-on,runner=4cpu-linux-x64
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/prepare-repository

- name: Run lint checker
run: yarn lint:check

publish:
runs-on: runs-on,runner=4cpu-linux-x64
Synicalx marked this conversation as resolved.
Show resolved Hide resolved
if: github.event_name == 'release'
needs:
- test
- lint-check
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/prepare-repository

- name: Authenticate with NPM registry
run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc

- name: Publish
run: npm publish --access=public
Loading