Skip to content

Commit

Permalink
fix: use file instead
Browse files Browse the repository at this point in the history
Actions cannot read teams and this also versions
changes.
  • Loading branch information
coderbyheart committed Apr 5, 2024
1 parent a64f31b commit 0c02c4e
Show file tree
Hide file tree
Showing 11 changed files with 443 additions and 41 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test-and-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,7 @@ jobs:
- name: Check if source code is properly formatted
run: npx prettier -c ./

- run: npm test

- name: Semantic release
run: npx semantic-release
3 changes: 2 additions & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
npx lint-staged
npx tsc
npx tsc
npm test
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Sets up the permissions in our AWS CI account for the repositories in this
GitHub organization that are supposed to have access so they are be able to use
it for CI runs.

The allowed list of repositories is managed via the
[`ci` team](https://github.com/orgs/hello-nrfcloud/teams/ci/repositories).
The allowed list of repositories is managed via the [`repos.txt`](./repos.txt)
file.

> [!CAUTION]
> Do not run this against the production account, but against the CI account.
Expand Down
3 changes: 2 additions & 1 deletion cdk/ci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { ensureGitHubOIDCProvider } from './ensureGitHubOIDCProvider.js'
import { fromEnv } from '@nordicsemiconductor/from-env'
import { CIApp } from './CIApp.js'
import { listRepos } from './listRepos.js'
import { loadRepoList } from './loadRepoList.js'

const { token } = fromEnv({
token: 'GITHUB_TOKEN',
})(process.env)

const repos = await listRepos(token, 'hello-nrfcloud', 'ci')
const repos = await listRepos(token, await loadRepoList())
for (const repo of repos) {
console.debug(`Setting up permissions for ${repo.name} (${repo.id})...`)
}
Expand Down
29 changes: 18 additions & 11 deletions cdk/listRepos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,27 @@ export type Repos = Array<Repository>

export const listRepos = async (
token: string,
org: string,
team: string,
): Promise<Array<Repository>> =>
(
await new Octokit({
auth: token,
}).teams.listReposInOrg({
org,
team_slug: team,
})
).data
repos: Array<Omit<Repository, 'id'>>,
): Promise<Array<Repository>> => {
const client = new Octokit({
auth: token,
})

return (
await Promise.all(
repos.map(async (repo) =>
client.repos.get({
repo: repo.name,
owner: repo.owner,
}),
),
)
)
.map((res) => res.data)
.filter((repo) => repo.archived !== true)
.map((repo) => ({
id: repo.id,
name: repo.name,
owner: repo.full_name.split('/')[0] as string,
}))
}
14 changes: 14 additions & 0 deletions cdk/loadRepoList.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import { loadRepoList } from './loadRepoList.js'

void describe('loadRepoList()', () => {
void it('should load the list of repos', async () => {
assert.notEqual(
(await loadRepoList()).find(
(el) => el.name === 'ci' && el.owner === 'hello-nrfcloud',
),
undefined,
)
})
})
13 changes: 13 additions & 0 deletions cdk/loadRepoList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import path from 'node:path'
import { readFile } from 'node:fs/promises'
import type { Repository } from './listRepos.js'

export const loadRepoList = async (): Promise<Array<Omit<Repository, 'id'>>> =>
(await readFile(path.join(process.cwd(), 'repos.txt'), 'utf-8'))
.trim()
.split('\n')
.filter((s) => !s.startsWith('#'))
.map((s) => {
const [owner, name] = s.split('/') as [string, string]
return { owner, name }
})
Loading

0 comments on commit 0c02c4e

Please sign in to comment.