-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
77a8554
commit 9c4bf76
Showing
4 changed files
with
179 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
name: Update issue | ||
|
||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: '* 7 * * *' | ||
permissions: | ||
issues: write | ||
id-token: write | ||
jobs: | ||
update-issue: | ||
name: Update issue | ||
timeout-minutes: 15 | ||
runs-on: ubuntu-latest | ||
environment: fprd | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 # Required to fetch range | ||
|
||
- name: Install Dependencies | ||
run: npm i -g pnpm typescript && pnpm i | ||
|
||
- name: 'Login to Azure' | ||
uses: azure/login@v1 | ||
with: | ||
client-id: ${{ secrets.AZURE_CLIENT_ID }} | ||
tenant-id: ${{ secrets.AZURE_TENANT_ID }} | ||
allow-no-subscriptions: true | ||
|
||
- name: 'Obtain fusion token' | ||
shell: bash | ||
run: echo "FUSION_TOKEN=$(az account get-access-token --resource '${{ secrets.AZURE_RESOURCE_ID }}' | jq '.accessToken')" >> $GITHUB_ENV | ||
|
||
- name: 'Login to Azure' | ||
uses: azure/login@v1 | ||
with: | ||
client-id: ${{ secrets.AZURE_PROD_CLIENT_ID }} | ||
tenant-id: ${{ secrets.AZURE_TENANT_ID }} | ||
allow-no-subscriptions: true | ||
|
||
- name: 'Obtain fusion token' | ||
shell: bash | ||
run: echo "FUSION_PROD_TOKEN=$(az account get-access-token --resource '${{ secrets.AZURE_RESOURCE_PROD_ID }}' | jq '.accessToken')" >> $GITHUB_ENV | ||
|
||
- name: 'Update issue' | ||
shell: bash | ||
run: npx ts-node --esm ./github-action/src/issue.ts issue -T ${{ github.token }} -C ${{env.FUSION_TOKEN}} -F ${{env.FUSION_PROD_TOKEN}} |
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,124 @@ | ||
#!/usr/bin/env node | ||
|
||
import { Command } from 'commander'; | ||
import { setSecret } from '@actions/core'; | ||
import { getOctokit, context } from '@actions/github'; | ||
import { markdownTable } from 'markdown-table'; | ||
import { logInfo } from './utils/logInfo.js'; | ||
const prodUrl = 'https://fusion-s-portal-fprd.azurewebsites.net'; | ||
const ciUrl = 'https://fusion-s-portal-ci.azurewebsites.net'; | ||
const program = new Command(); | ||
|
||
program.name('Issue'); | ||
|
||
program | ||
.command('issue') | ||
.option('-T, --token <token>', 'change the working directory') | ||
.option('-C --ci <ci>', 'Fusion CI token') | ||
.option('-F --fprd <fprd>', 'Fusion prod token') | ||
.action(async (args) => { | ||
if (!args.token) { | ||
throw new Error('Missing github token'); | ||
} | ||
if (!args.ci) { | ||
throw new Error('Missing ci token'); | ||
} | ||
if (!args.fprd) { | ||
throw new Error('Missing fprd token'); | ||
} | ||
setSecret(args.token); | ||
setSecret(args.ci); | ||
setSecret(args.fprd); | ||
release(args.token, args.ci, args.fprd); | ||
}); | ||
|
||
await program.parseAsync(); | ||
|
||
type FusionAppStatus = { | ||
key: string; | ||
name: string; | ||
publishedTest: string; | ||
publishedProd: string; | ||
}; | ||
|
||
export async function release(token: string, ciToken: string, fprdToken: string) { | ||
const client = getOctokit(token); | ||
|
||
const ciApps = await getFusionApps(ciUrl, ciToken); | ||
const fprdApps = await getFusionApps(prodUrl, fprdToken); | ||
|
||
const appStatus = ciApps | ||
.map((s) => s.key) | ||
.concat(fprdApps.map((s) => s.key)) | ||
.filter((v, i, a) => a.indexOf(v) === i) | ||
.map((x): FusionAppStatus => { | ||
const maybeCiApp = ciApps.find((s) => s.key === x); | ||
|
||
const maybeProdApp = fprdApps.find((s) => s.key === x); | ||
return { | ||
key: x, | ||
name: maybeCiApp?.name ?? maybeProdApp?.name ?? x, | ||
publishedProd: !!maybeProdApp?.isPublished | ||
? `${new Date(maybeProdApp.publishedDate).toLocaleDateString('en-gb')} ✅` | ||
: '❌', | ||
publishedTest: !!maybeCiApp?.isPublished | ||
? `${new Date(maybeCiApp.publishedDate).toLocaleDateString('en-gb')} ✅` | ||
: '❌', | ||
}; | ||
}); | ||
|
||
const table = markdownTable([ | ||
['Key', 'Name', 'Test', 'Prod'], | ||
...appStatus.map((s) => [s.key, s.name, s.publishedTest, s.publishedProd]), | ||
]); | ||
|
||
const res = await client.rest.issues.update({ | ||
issue_number: 693, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
title: 'Fusion app status', | ||
body: table, | ||
}); | ||
|
||
if (res.status !== 200) { | ||
logInfo(res.status, 'Red'); | ||
throw new Error('Failed to update issue'); | ||
} | ||
} | ||
|
||
export async function getFusionApps( | ||
baseUrl: string, | ||
token: string | ||
): Promise<IssueFusionApp[]> { | ||
const headers = { | ||
['content-type']: 'application/json', | ||
['Authorization']: `Bearer ${token}`, | ||
}; | ||
|
||
const res = await fetch(`${baseUrl}/api/admin/apps`, { | ||
headers: headers, | ||
}); | ||
|
||
const data = (await res.json()).map( | ||
(s: FusionApp): IssueFusionApp => ({ | ||
name: s.name, | ||
key: s.key, | ||
isPublished: !!s.publishedDate, | ||
publishedDate: s.publishedDate, | ||
}) | ||
); | ||
return data; | ||
} | ||
|
||
type FusionApp = { | ||
name: string; | ||
key: string; | ||
publishedDate: string | null; | ||
}; | ||
|
||
type IssueFusionApp = { | ||
name: string; | ||
key: string; | ||
isPublished: boolean; | ||
publishedDate: string | null; | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.