Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:

testint:
runs-on: ubuntu-latest
# only run if not a fork PR targeting main repo due to permissions
Copy link
Member

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.

Copy link
Contributor Author

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

if: ${{ !(github.head_repo || github.event.pull_request.head.repo) || github.repository == (github.head_repo.full_name || github.event.pull_request.head.repo.full_name) }}
steps:
- uses: actions/checkout@v4
- name: Use Node.js 24
Expand All @@ -36,9 +38,13 @@ jobs:
- run: npm install
- run: npm run test:integration
env:
GITHUB_TOKEN: ${{ secrets.INT_TEST_TOKEN }}
GITHUB_TOKEN: ${{ secrets.INT_TEST_TOKEN != '' && secrets.INT_TEST_TOKEN || secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_HEAD_REPO: ${{ github.head_repo && github.head_repo.full_name || github.event.pull_request.head.repo.full_name || '' }}
action-in-action:
runs-on: ubuntu-latest
# only run if not a fork PR targeting main repo due to permissions
if: ${{ !(github.head_repo || github.event.pull_request.head.repo) || github.repository == (github.head_repo.full_name || github.event.pull_request.head.repo.full_name) }}
steps:
- uses: actions/checkout@v4
- name: Use Node.js 24
Expand All @@ -48,6 +54,9 @@ jobs:
- run: npm install
- uses: ./
id: maker
env:
TEST_REPOS: ${{ github.repository != 'pkgjs/meet' && github.repository || 'pkgjs/meet,pkgjs/meet' }}
TEST_ORGS: ${{ github.repository != 'pkgjs/meet' && '' || 'pkgjs' }}
with:
token: ${{ secrets.GITHUB_TOKEN }}
schedules: 2020-04-02T17:00:00.0Z/P1D
Expand All @@ -57,7 +66,7 @@ jobs:
agendaLabel: meeting-agenda-test
meetingLink: https://github.com/pkgjs/meet
createNotes: true
repos: pkgjs/meet,pkgjs/meet
orgs: pkgjs
repos: ${{ env.TEST_REPOS }}
orgs: ${{ env.TEST_ORGS }}
- name: clean up issue
run: node ./test/_close-issue.js ${{ secrets.GITHUB_TOKEN }} ${{ steps.maker.outputs.issueNumber }}
7 changes: 5 additions & 2 deletions test/_close-issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ const issues = require('../lib/issues')
if (!issueNumber) {
return
}
console.log(`Closing test issue ${issueNumber}`)

const client = getOctokit(token)
const repo = context.repo

console.log(`Closing test issue ${issueNumber} in ${repo.owner}/${repo.repo}`)

await issues.closeIssue(client, issueNumber, {
...context.repo
...repo
})
})(process.argv)
50 changes: 41 additions & 9 deletions test/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ✨
Copy link
Member

Choose a reason for hiding this comment

The 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',
Expand All @@ -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'])
Expand All @@ -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
Expand All @@ -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'
})
Expand Down