-
Notifications
You must be signed in to change notification settings - Fork 10
💚 fix CI runs for fork PRs #240
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,15 +11,47 @@ const { getOctokit } = require('@actions/github') | |
const pkg = require('../package.json') | ||
const meetings = require('../lib/meetings') | ||
|
||
const mainRepo = 'pkgjs/meet' | ||
|
||
function getTestRepo () { | ||
let testRepo = { owner: 'wesleytodd', repo: 'meeting-maker' } // ✨ Wes, the meeting maker ✨ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤣 |
||
|
||
if (process.env.GITHUB_REPOSITORY) { | ||
// we appear to be in a GH action | ||
if (process.env.GITHUB_REPOSITORY !== mainRepo) { | ||
// action running in a fork | ||
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/') | ||
testRepo = { owner, repo } | ||
} else if (process.env.GITHUB_HEAD_REPO && | ||
process.env.GITHUB_HEAD_REPO !== mainRepo) { | ||
// action running in a fork PR targeting main repo | ||
// skip tests - GH token doesn't have write permissions for either repo | ||
throw new Error('skipping integration tests: fork PR targeting main repo (no permissions)') | ||
} | ||
} | ||
|
||
console.log(`using repository ${testRepo.owner}/${testRepo.repo}`) | ||
return testRepo | ||
} | ||
|
||
suite(`${pkg.name} integration`, () => { | ||
let client | ||
let testRepo | ||
|
||
before(() => { | ||
client = getOctokit(process.env.GITHUB_TOKEN) | ||
const token = process.env.GITHUB_TOKEN | ||
if (!token) { | ||
throw new Error('GITHUB_TOKEN environment variable is required for integration tests') | ||
} | ||
|
||
client = getOctokit(token) | ||
testRepo = getTestRepo() | ||
}) | ||
|
||
test('should create next meeting issue', async () => { | ||
const issue = await meetings.shouldCreateNextMeetingIssue(client, { | ||
owner: 'wesleytodd', | ||
repo: 'meeting-maker', | ||
owner: testRepo.owner, | ||
repo: testRepo.repo, | ||
issueTitle: ({ date }) => `Test Meeting ${date.toZonedDateTimeISO('UTC').toPlainDate().toString()}`, | ||
createWithin: 'P7D', | ||
agendaLabel: 'meeting-agenda', | ||
|
@@ -30,8 +62,8 @@ suite(`${pkg.name} integration`, () => { | |
now: Temporal.Instant.from('2020-04-13T13:00:00.0Z'), | ||
meetingLabels: ['testMeeting', 'test'] | ||
}) | ||
assert.deepStrictEqual(issue.owner, 'wesleytodd') | ||
assert.deepStrictEqual(issue.repo, 'meeting-maker') | ||
assert.deepStrictEqual(issue.owner, testRepo.owner) | ||
assert.deepStrictEqual(issue.repo, testRepo.repo) | ||
assert.deepStrictEqual(issue.title, `Test Meeting ${Temporal.Instant.from('2020-04-16T13:00:00.0Z').toZonedDateTimeISO('UTC').toPlainDate().toString()}`) | ||
assert.deepStrictEqual(issue.agendaLabel, 'meeting-agenda') | ||
assert.deepStrictEqual(issue.labels, ['testMeeting', 'test']) | ||
|
@@ -41,8 +73,8 @@ suite(`${pkg.name} integration`, () => { | |
|
||
test('create next meeting issue', async () => { | ||
const issue = await meetings.createNextMeeting(client, { | ||
owner: 'wesleytodd', | ||
repo: 'meeting-maker', | ||
owner: testRepo.owner, | ||
repo: testRepo.repo, | ||
createWithin: 'P7D', | ||
schedules: [ | ||
// 5pm GMT April 2 repeating every 28 days | ||
|
@@ -60,8 +92,8 @@ suite(`${pkg.name} integration`, () => { | |
assert.deepStrictEqual(issue.data.state, 'open') | ||
|
||
await client.rest.issues.update({ | ||
owner: 'wesleytodd', | ||
repo: 'meeting-maker', | ||
owner: testRepo.owner, | ||
repo: testRepo.repo, | ||
issue_number: issue.data.number, | ||
state: 'closed' | ||
}) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fwiw I am not sure this comment is any more clear than the code lol. Just to make sure I understand what you are saying here:
This checks to see if you are making a fork targeting your fork, not this repo?
If so, that seems like a reasonable middle ground to allow testing without leaking secrets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fork PR -> fork repo -> run test
fork PR -> main repo -> skip test