Skip to content

Commit

Permalink
ci(feat): reusable workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
nebolsin committed Jun 16, 2023
1 parent 944646d commit 76ed4df
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 124 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/coveralls-standalone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Standalone Coveralls Report

on: [ pull_request ]

# In this workflow we will:
# - wait for all sibling workflows to finish
# - download artifacts with coverage reports from `coveralls` workflow
# - send acquired artifacts to Coveralls as single report
jobs:
report:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Wait on tests (PR)
uses: lewagon/[email protected]
with:
# NOTE: The ref value should be different when triggered by pull_request event.
# See: https://github.com/lewagon/wait-on-check-action/issues/25.
ref: ${{ github.event.pull_request.head.sha }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
wait-interval: 10 # seconds
running-workflow-name: report # the name of this job
allowed-conclusions: success,skipped,cancelled,failure

- name: Download artifact
id: download-artifact
uses: dawidd6/action-download-artifact@v2
with:
github_token: ${{secrets.GITHUB_TOKEN}}
pr: ${{github.event.pull_request.number}}
workflow: coveralls.yml
workflow_conclusion: success

- uses: coverallsapp/github-action@v2
with:
format: lcov
debug: true
57 changes: 27 additions & 30 deletions .github/workflows/coveralls.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,33 @@
name: Coveralls report
name: Test all platforms

on: [ push, pull_request ]

jobs:
report:
runs-on: ubuntu-latest
steps:
# NOTE: The ref value should be different when triggered by pull_request event.
# See: https://github.com/lewagon/wait-on-check-action/issues/25.
- name: Wait on tests (PR)
uses: lewagon/[email protected]
if: github.event_name == 'pull_request'
with:
ref: ${{ github.event.pull_request.head.sha }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
wait-interval: 10 # seconds
running-workflow-name: report # the name of this job
allowed-conclusions: success,skipped,cancelled,failure
test-linux:
uses: ./.github/workflows/test.yml
secrets:
token: ${{ secrets.COVERALLS_REPO_TOKEN }}

test-macos:
uses: ./.github/workflows/test.yml
with:
os: macos
secrets:
token: ${{ secrets.COVERALLS_REPO_TOKEN }}

- name: Wait on tests (push)
if: github.event_name != 'pull_request'
uses: lewagon/[email protected]
with:
ref: ${{ github.sha }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
wait-interval: 10 # seconds
running-workflow-name: report # this job name
allowed-conclusions: success,skipped,cancelled,failure
test-windows:
uses: ./.github/workflows/test.yml
with:
os: windows
secrets:
token: ${{ secrets.COVERALLS_REPO_TOKEN }}

- uses: coverallsapp/github-action@v2
env:
COVERALLS_SERVICE_NUMBER: ${{ github.sha }}
with:
carryforward: "linux-1,linux-2,macos-2,macos-2,windows-1,windows-1"
parallel-finished: true
coveralls:
runs-on: ubuntu-latest
if: ${{ always() }}
needs: [test-linux, test-macos, test-windows]
steps:
- uses: coverallsapp/github-action@v2
with:
carryforward: "linux-1,linux-2,macos-2,macos-2,windows-1,windows-1"
parallel-finished: true
30 changes: 0 additions & 30 deletions .github/workflows/linux.yml

This file was deleted.

31 changes: 0 additions & 31 deletions .github/workflows/macos.yml

This file was deleted.

64 changes: 64 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Reusable test workflow
run-name: Run tests on ${{ inputs.os }}

on:
workflow_call:
inputs:
build_id:
type: string
default: ${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}
description: |
Build identifier for the current run. This is sent as `service_number` to Coveralls.
os:
type: string
default: ubuntu
description: |
The type of machine to run the job on. Can be one of 'ubuntu' (default), 'macos', or 'windows'.
upload_coverage:
type: boolean
default: true
description: |
Whether to upload the coverage data to Coveralls.
store_coverage:
type: boolean
default: true
description: |
Whether to store the coverage data as an artifact.
secrets:
token:
required: true

env:
COVERALLS_SERVICE_NUMBER: ${{ inputs.build_id }}
COVERALLS_REPO_TOKEN: ${{ secrets.token }}

jobs:
test:
runs-on: ${{ inputs.os }}-latest
strategy:
matrix:
test_number: [ 1, 2 ]
outputs:
build_id: ${{ inputs.build_id }}
result: ${{ steps.coveralls.outputs.coveralls-api-result}}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: lts/*
cache: npm
- run: npm ci
- run: npm test -- test/run${{ matrix.test_number }}.js
- name: Coveralls
id: coveralls
if: ${{ inputs.upload_coverage }}
uses: coverallsapp/github-action@v2
with:
parallel: true
flag-name: ${{ inputs.os }}-${{ matrix.test_number }}
debug: true
- uses: actions/upload-artifact@v3
if: ${{ inputs.store_coverage }}
with:
name: coverage-data-${{ inputs.os }}-${{ matrix.test_number }}
path: coverage/
30 changes: 0 additions & 30 deletions .github/workflows/windows.yml

This file was deleted.

17 changes: 14 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
sudo: false
---
os: linux
dist: jammy

language: node_js
node_js:
- "node"
node_js: lts/*
cache:
directories: ~/.npm

before_script: npm install -g npm@latest

env:
global:
- COVERALLS_PARALLEL=true

install: npm ci

jobs:
include:
- script: npm test -- test/run1.js && COVERALLS_FLAG_NAME=test-1 npm run upload-coverage
- script: npm test -- test/run2.js && COVERALLS_FLAG_NAME=test-2 npm run upload-coverage

notifications:
webhooks: https://coveralls.io/webhook

0 comments on commit 76ed4df

Please sign in to comment.