Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
Merge pull request #160 from ibrahim0814/ib/add-ga
Browse files Browse the repository at this point in the history
Add Github Actions support
  • Loading branch information
thomasrockhu committed Sep 16, 2020
2 parents af2d353 + 3bc49d4 commit 33300b5
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 3 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/nodejs.yml
@@ -1,18 +1,17 @@
name: Node CI

on: [push]
on: [push, pull_request]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [10.x, 12.x, 14.x]

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
Expand All @@ -24,3 +23,5 @@ jobs:
npm test
env:
CI: true
- name: Upload coverage to Codecov
run: ./bin/codecov
1 change: 1 addition & 0 deletions lib/detect.js
Expand Up @@ -16,6 +16,7 @@ var services = {
heroku: require('./services/heroku'),
teamcity: require('./services/teamcity'),
codebuild: require('./services/codebuild'),
github_actions: require('./services/github_actions'),
}

var detectProvider = function() {
Expand Down
27 changes: 27 additions & 0 deletions lib/services/github_actions.js
@@ -0,0 +1,27 @@
module.exports = {
detect: function() {
return !!process.env.GITHUB_ACTIONS
},

configuration: function() {
// https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables
console.log(' GitHub Actions CI Detected')

var params = {
branch:
process.env.GITHUB_HEAD_REF ||
process.env.GITHUB_REF.replace('refs/heads/', ''),
build: process.env.GITHUB_RUN_ID,
commit: process.env.GITHUB_SHA,
service: 'github-actions',
slug: process.env.GITHUB_REPOSITORY,
}

if (process.env.GITHUB_HEAD_REF) {
// PR refs are in the format: refs/pull/7/merge for pull_request events
params['pr'] = process.env.GITHUB_REF.split('/')[2]
}

return params
},
}
41 changes: 41 additions & 0 deletions test/services/github_actions.test.js
@@ -0,0 +1,41 @@
var github_actions = require('../../lib/services/github_actions')

describe('GitHub Actions CI Provider', function() {
it('can detect GitHub Actions', function() {
process.env.GITHUB_ACTIONS = '1'
expect(github_actions.detect()).toBe(true)
})

it('can get GitHub Actions env info on push event', function() {
delete process.env.GITHUB_HEAD_REF
process.env.GITHUB_REF = 'refs/heads/master'
process.env.GITHUB_REPOSITORY = 'codecov/codecov-repo'
process.env.GITHUB_RUN_ID = '257701960'
process.env.GITHUB_SHA = '743b04806ea677403aa2ff26c6bdeb85005de658'

expect(github_actions.configuration()).toEqual({
branch: 'master',
build: '257701960',
commit: '743b04806ea677403aa2ff26c6bdeb85005de658',
service: 'github-actions',
slug: 'codecov/codecov-repo',
})
})

it('can get GitHub Actions env info on pull request', function() {
process.env.GITHUB_HEAD_REF = 'develop'
process.env.GITHUB_REF = 'refs/pull/7/merge'
process.env.GITHUB_REPOSITORY = 'codecov/codecov-repo'
process.env.GITHUB_RUN_ID = '257701960'
process.env.GITHUB_SHA = '743b04806ea677403aa2ff26c6bdeb85005de658'

expect(github_actions.configuration()).toEqual({
branch: 'develop',
build: '257701960',
commit: '743b04806ea677403aa2ff26c6bdeb85005de658',
pr: '7',
service: 'github-actions',
slug: 'codecov/codecov-repo',
})
})
})

0 comments on commit 33300b5

Please sign in to comment.