Skip to content

Commit

Permalink
fix: Use GitHub personal access token to retrieve artifacts.
Browse files Browse the repository at this point in the history
  • Loading branch information
na2axl committed Oct 6, 2024
1 parent 03c4673 commit f108d0e
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 13 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ jobs:
x64-osx
x64-linux
version: nightly
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Print Output
id: output
run: echo "${{ steps.test-action.outputs.time }}"
run: |
echo "${{ steps.test-action.outputs.x64_windows_nightly }}"
echo "${{ steps.test-action.outputs.x64_osx_nightly }}"
echo "${{ steps.test-action.outputs.x64_linux_nightly }}"
8 changes: 4 additions & 4 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let setFailedMock: jest.SpiedFunction<typeof core.setFailed>
let setOutputMock: jest.SpiedFunction<typeof core.setOutput>

let downloadToolMock: jest.SpiedFunction<typeof tc.downloadTool>
let extract7z: jest.SpiedFunction<typeof tc.extract7z>
let extractZipMock: jest.SpiedFunction<typeof tc.extractZip>

describe('action', () => {
beforeEach(() => {
Expand All @@ -38,10 +38,10 @@ describe('action', () => {
setOutputMock = jest.spyOn(core, 'setOutput').mockImplementation()

downloadToolMock = jest.spyOn(tc, 'downloadTool').mockImplementation()
extract7z = jest.spyOn(tc, 'extract7z').mockImplementation()
extractZipMock = jest.spyOn(tc, 'extractZip').mockImplementation()

downloadToolMock.mockImplementation(async () => 'path/to/sdk.7z')
extract7z.mockImplementation(async () => 'path/to/sdk')
downloadToolMock.mockImplementation(async () => 'path/to/sdk.zip')
extractZipMock.mockImplementation(async () => 'path/to/sdk')
})

it('downloads the nightly artifacts', async () => {
Expand Down
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 9 additions & 3 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

18 changes: 15 additions & 3 deletions src/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@ async function downloadNightly(platforms: Platform[]): Promise<void> {
const artifactsUrl =
'https://api.github.com/repos/AmplitudeAudio/sdk/actions/artifacts'

let headers: Record<string, string> = {}

if (process.env.GITHUB_TOKEN !== undefined) {
headers = {
Authorization: `token ${process.env.GITHUB_TOKEN}`
}
}

core.debug('Retrieving artifacts from GitHub Actions')
const response = await fetch(artifactsUrl)
const response = await fetch(artifactsUrl, { headers })
if (!response.ok) {
throw new Error(`Failed to fetch artifacts: ${response.status}`)
}
Expand All @@ -44,8 +52,12 @@ async function downloadNightly(platforms: Platform[]): Promise<void> {
}

const downloadUrl = artifact.archive_download_url
const downloadedPath = await tc.downloadTool(downloadUrl)
const extractedFolder = await tc.extract7z(downloadedPath)
const downloadedPath = await tc.downloadTool(
downloadUrl,
'./artifacts',
headers.Authorization
)
const extractedFolder = await tc.extractZip(downloadedPath)

core.addPath(extractedFolder)
core.info(`Downloaded ${platform} nightly build to ${extractedFolder}`)
Expand Down

0 comments on commit f108d0e

Please sign in to comment.