From 1109eefb8c266bfc52092f93c1a50c82242c9bfd Mon Sep 17 00:00:00 2001 From: ibrahim0814 Date: Wed, 13 Nov 2019 01:31:05 -0800 Subject: [PATCH 01/11] add github actions support --- lib/detect.js | 1 + lib/services/github_actions.js | 20 ++++++++++++++++++++ test/services/github_actions.test.js | 21 +++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 lib/services/github_actions.js create mode 100644 test/services/github_actions.test.js diff --git a/lib/detect.js b/lib/detect.js index e40e0f1c..7c2e9348 100644 --- a/lib/detect.js +++ b/lib/detect.js @@ -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() { diff --git a/lib/services/github_actions.js b/lib/services/github_actions.js new file mode 100644 index 00000000..031b71c7 --- /dev/null +++ b/lib/services/github_actions.js @@ -0,0 +1,20 @@ +module.exports = { + detect: () => { + return !!process.env.GITHUB_ACTIONS + }, + + configuration: () => { + console.log(' GitHub Actions CI Detected') + return { + service: 'github_actions', + commit: process.env.GITHUB_SHA, + branch: getBranch(), + slug: process.env.GITHUB_REPOSITORY, + } + + getBranch = () => { + let currRef = process.env.GITHUB_REF + return currRef.replace("refs/heads/", "") + } + }, + } \ No newline at end of file diff --git a/test/services/github_actions.test.js b/test/services/github_actions.test.js new file mode 100644 index 00000000..56cc19b5 --- /dev/null +++ b/test/services/github_actions.test.js @@ -0,0 +1,21 @@ +var github_actions = require('../../lib/services/github_actions') + +describe('GitHub Actions CI Provider', () => { + it('can detect GitHub Actions', () => { + process.env.GITHUB_ACTIONS = true + expect(github_actions.detect()).to.be(true) + }) + + it('can get GitHub Actions env info', () => { + process.env.GITHUB_SHA = '743b04806ea677403aa2ff26c6bdeb85005de658' + process.env.GITHUB_REPOSITORY = 'codecov/codecov-repo' + process.env.GITHUB_REF = 'refs/heads/master' + + expect(github_actions.configuration()).to.eql({ + service: 'github_actions', + commit: '743b04806ea677403aa2ff26c6bdeb85005de658', + branch: 'master', + slug: 'codecov/codecov-repo', + }) + }) +}) \ No newline at end of file From 8482b3a1cc338993ec7c845506eb145cedb789a5 Mon Sep 17 00:00:00 2001 From: ibrahim0814 Date: Wed, 13 Nov 2019 01:44:59 -0800 Subject: [PATCH 02/11] use const instead of var --- test/services/github_actions.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/services/github_actions.test.js b/test/services/github_actions.test.js index 56cc19b5..3315240b 100644 --- a/test/services/github_actions.test.js +++ b/test/services/github_actions.test.js @@ -1,4 +1,4 @@ -var github_actions = require('../../lib/services/github_actions') +const github_actions = require('../../lib/services/github_actions') describe('GitHub Actions CI Provider', () => { it('can detect GitHub Actions', () => { From a8fde3cfb894db7f1d716ac6dad85f93f5828e30 Mon Sep 17 00:00:00 2001 From: ibrahim0814 Date: Wed, 13 Nov 2019 01:49:58 -0800 Subject: [PATCH 03/11] change syntax, remove arrow functions --- lib/services/github_actions.js | 11 +++-------- test/services/github_actions.test.js | 8 ++++---- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/services/github_actions.js b/lib/services/github_actions.js index 031b71c7..55e0a81b 100644 --- a/lib/services/github_actions.js +++ b/lib/services/github_actions.js @@ -1,20 +1,15 @@ module.exports = { - detect: () => { + detect: function() { return !!process.env.GITHUB_ACTIONS }, - configuration: () => { + configuration: function() { console.log(' GitHub Actions CI Detected') return { service: 'github_actions', commit: process.env.GITHUB_SHA, - branch: getBranch(), + branch: process.env.GITHUB_REF.replace("refs/heads/", ""), slug: process.env.GITHUB_REPOSITORY, } - - getBranch = () => { - let currRef = process.env.GITHUB_REF - return currRef.replace("refs/heads/", "") - } }, } \ No newline at end of file diff --git a/test/services/github_actions.test.js b/test/services/github_actions.test.js index 3315240b..3fa2d8d1 100644 --- a/test/services/github_actions.test.js +++ b/test/services/github_actions.test.js @@ -1,12 +1,12 @@ -const github_actions = require('../../lib/services/github_actions') +var github_actions = require('../../lib/services/github_actions') -describe('GitHub Actions CI Provider', () => { - it('can detect GitHub Actions', () => { +describe('GitHub Actions CI Provider', function() { + it('can detect GitHub Actions', function() { process.env.GITHUB_ACTIONS = true expect(github_actions.detect()).to.be(true) }) - it('can get GitHub Actions env info', () => { + it('can get GitHub Actions env info', function() { process.env.GITHUB_SHA = '743b04806ea677403aa2ff26c6bdeb85005de658' process.env.GITHUB_REPOSITORY = 'codecov/codecov-repo' process.env.GITHUB_REF = 'refs/heads/master' From f18cefadd9796f823cc1fe23082944c8c63c0b63 Mon Sep 17 00:00:00 2001 From: ibrahim0814 Date: Wed, 13 Nov 2019 02:02:16 -0800 Subject: [PATCH 04/11] change from bool to 1 --- test/services/github_actions.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/services/github_actions.test.js b/test/services/github_actions.test.js index 3fa2d8d1..fd81640f 100644 --- a/test/services/github_actions.test.js +++ b/test/services/github_actions.test.js @@ -2,7 +2,7 @@ var github_actions = require('../../lib/services/github_actions') describe('GitHub Actions CI Provider', function() { it('can detect GitHub Actions', function() { - process.env.GITHUB_ACTIONS = true + process.env.GITHUB_ACTIONS = '1' expect(github_actions.detect()).to.be(true) }) From e9bd32b397cf2674cddd8d28c4c829db489a18e8 Mon Sep 17 00:00:00 2001 From: Ibrahim Ali Date: Fri, 31 Jan 2020 11:28:55 -0600 Subject: [PATCH 05/11] fix jest assertions --- test/services/github_actions.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/services/github_actions.test.js b/test/services/github_actions.test.js index fd81640f..c01472d3 100644 --- a/test/services/github_actions.test.js +++ b/test/services/github_actions.test.js @@ -3,7 +3,7 @@ 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()).to.be(true) + expect(github_actions.detect()).toBe(true) }) it('can get GitHub Actions env info', function() { @@ -11,11 +11,11 @@ describe('GitHub Actions CI Provider', function() { process.env.GITHUB_REPOSITORY = 'codecov/codecov-repo' process.env.GITHUB_REF = 'refs/heads/master' - expect(github_actions.configuration()).to.eql({ + expect(github_actions.configuration()).toEqual({ service: 'github_actions', commit: '743b04806ea677403aa2ff26c6bdeb85005de658', branch: 'master', slug: 'codecov/codecov-repo', }) }) -}) \ No newline at end of file +}) From b3397c89aa2863d9c0b28dda8a268944e1554aa0 Mon Sep 17 00:00:00 2001 From: Ibrahim Ali Date: Sat, 1 Feb 2020 11:59:12 -0600 Subject: [PATCH 06/11] Update github_actions.js --- lib/services/github_actions.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/services/github_actions.js b/lib/services/github_actions.js index 55e0a81b..f78b93b4 100644 --- a/lib/services/github_actions.js +++ b/lib/services/github_actions.js @@ -6,10 +6,10 @@ module.exports = { configuration: function() { console.log(' GitHub Actions CI Detected') return { - service: 'github_actions', + service: 'github-actions', commit: process.env.GITHUB_SHA, branch: process.env.GITHUB_REF.replace("refs/heads/", ""), slug: process.env.GITHUB_REPOSITORY, } }, - } \ No newline at end of file + } From ef55637ab0c3f8de9fc5fa460a7382c05f735236 Mon Sep 17 00:00:00 2001 From: Ibrahim Ali Date: Sat, 1 Feb 2020 11:59:37 -0600 Subject: [PATCH 07/11] correct service name --- test/services/github_actions.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/services/github_actions.test.js b/test/services/github_actions.test.js index c01472d3..65f4ef50 100644 --- a/test/services/github_actions.test.js +++ b/test/services/github_actions.test.js @@ -12,7 +12,7 @@ describe('GitHub Actions CI Provider', function() { process.env.GITHUB_REF = 'refs/heads/master' expect(github_actions.configuration()).toEqual({ - service: 'github_actions', + service: 'github-actions', commit: '743b04806ea677403aa2ff26c6bdeb85005de658', branch: 'master', slug: 'codecov/codecov-repo', From aae70444dafd841960d170ca7ab859fb921e5c61 Mon Sep 17 00:00:00 2001 From: Thomas Hu Date: Wed, 16 Sep 2020 10:39:01 -0400 Subject: [PATCH 08/11] Add more params --- lib/services/github_actions.js | 40 ++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/lib/services/github_actions.js b/lib/services/github_actions.js index f78b93b4..8ed08806 100644 --- a/lib/services/github_actions.js +++ b/lib/services/github_actions.js @@ -1,15 +1,27 @@ module.exports = { - detect: function() { - return !!process.env.GITHUB_ACTIONS - }, - - configuration: function() { - console.log(' GitHub Actions CI Detected') - return { - service: 'github-actions', - commit: process.env.GITHUB_SHA, - branch: process.env.GITHUB_REF.replace("refs/heads/", ""), - slug: process.env.GITHUB_REPOSITORY, - } - }, - } + 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 + }, +} From f033b57e9024d8d1c3a0511a09e3b5a2efc33a7a Mon Sep 17 00:00:00 2001 From: Thomas Hu Date: Wed, 16 Sep 2020 10:43:11 -0400 Subject: [PATCH 09/11] Edit workflow --- .github/workflows/nodejs.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 68f755c5..480871d9 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -1,10 +1,9 @@ name: Node CI -on: [push] +on: [push, pull_request] jobs: build: - runs-on: ubuntu-latest strategy: @@ -12,7 +11,7 @@ jobs: 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: @@ -24,3 +23,5 @@ jobs: npm test env: CI: true + - name: Upload coverage to Codecov + run: ./bin/codecov From 02c90145a3b33a77158ea48b8915f4e35b494158 Mon Sep 17 00:00:00 2001 From: Thomas Hu Date: Wed, 16 Sep 2020 10:51:20 -0400 Subject: [PATCH 10/11] Fix tests --- test/services/github_actions.test.js | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/test/services/github_actions.test.js b/test/services/github_actions.test.js index 65f4ef50..672438bc 100644 --- a/test/services/github_actions.test.js +++ b/test/services/github_actions.test.js @@ -6,15 +6,34 @@ describe('GitHub Actions CI Provider', function() { expect(github_actions.detect()).toBe(true) }) - it('can get GitHub Actions env info', function() { - process.env.GITHUB_SHA = '743b04806ea677403aa2ff26c6bdeb85005de658' - process.env.GITHUB_REPOSITORY = 'codecov/codecov-repo' + it('can get GitHub Actions env info on push event', function() { 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', - branch: 'master', + pr: '7', + service: 'github-actions', slug: 'codecov/codecov-repo', }) }) From 3bc49d4254a8b012017de3dbb3b79f3232535ea8 Mon Sep 17 00:00:00 2001 From: Thomas Hu Date: Wed, 16 Sep 2020 10:54:01 -0400 Subject: [PATCH 11/11] Fix other test --- test/services/github_actions.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/services/github_actions.test.js b/test/services/github_actions.test.js index 672438bc..73c886ef 100644 --- a/test/services/github_actions.test.js +++ b/test/services/github_actions.test.js @@ -7,6 +7,7 @@ describe('GitHub Actions CI Provider', function() { }) 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'