feat: add GitHub Actions support (#64)

* feat: support GitHub Actions

* chore: add test for GitHub Actions

* chore: mention GitHub Actions support in README
This commit is contained in:
Limon Monte
2019-11-16 03:50:18 +02:00
committed by Jake Bolam
parent f98f87fe6a
commit 8541f9c8af
3 changed files with 20 additions and 1 deletions

View File

@@ -85,7 +85,7 @@ The most efficient way to get this running is to ensure that some environment va
- `CI_COMMIT_SHA`
- `CI_BRANCH`
If you're using, _Travis_, _CircleCI_, _Wrecker_ or _Drone_ these should all work out of the box.
If you're using, _Travis_, _CircleCI_, _Wrecker_, _Drone_ or _GitHub Actions_ these should all work out of the box.
> Have a look at the source code to see which variables are automatically found: https://github.com/bundlewatch/bundlewatch/blob/master/src/app/config/getCIVars.js

View File

@@ -28,6 +28,11 @@ const getCIVars = env => {
commitSha = env.DRONE_COMMIT || env.CI_COMMIT
repoCurrentBranch = env.DRONE_COMMIT_BRANCH
repoBranchBase = env.DRONE_REPO_BRANCH
} else if (env.GITHUB_ACTIONS) {
repoOwner = env.GITHUB_REPOSITORY.split('/')[0]
repoName = env.GITHUB_REPOSITORY.split('/')[1]
commitSha = env.GITHUB_SHA
repoCurrentBranch = env.GITHUB_REF
}
// Take CI preffered vars over everything
repoOwner = env.CI_REPO_OWNER || repoOwner

View File

@@ -5,6 +5,7 @@ describe(`getCIVars`, () => {
const mockRepoName = 'reponame_mock'
const mockRepo = `${mockRepoOwner}/${mockRepoName}`
const mockBranchBase = `mock_branch_base`
const mockCommitSha = `ffac537e6cbbf934b08745a378932722df287a53`
it(`Extracts GIT_URL (ssh) correct`, () => {
const ciVars = getCIVars({
@@ -32,4 +33,17 @@ describe(`getCIVars`, () => {
})
expect(ciVars2.repoBranchBase || 'master').toBe('master')
})
it(`GitHub Actions is detected`, () => {
const ciVars = getCIVars({
GITHUB_ACTIONS: true,
GITHUB_REPOSITORY: mockRepo,
GITHUB_SHA: mockCommitSha,
GITHUB_REF: mockBranchBase,
})
expect(ciVars.repoOwner).toBe(mockRepoOwner)
expect(ciVars.repoName).toBe(mockRepoName)
expect(ciVars.commitSha).toBe(mockCommitSha)
expect(ciVars.repoCurrentBranch).toBe(mockBranchBase)
})
})