Skip to content

Commit

Permalink
Implement authentication for github api
Browse files Browse the repository at this point in the history
  • Loading branch information
Legion2 committed Nov 22, 2023
1 parent 90106da commit 8298031
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:
npm install
- run: |
npm run all
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
test: # make sure the action works on a clean machine without building
runs-on: ubuntu-latest
steps:
Expand All @@ -23,6 +25,7 @@ jobs:
with:
output: swagger-ui-output
spec-url: https://petstore.swagger.io/v2/swagger.json
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: "Verify swagger-ui was created"
run: |
test -f swagger-ui-output/index.html
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ In this case, it is your responsibility to copy required files such as the OpenA
The output directory of the generated Swagger UI must be set with the `output` argument of the Action.
Optionally the Swagger UI version can be set with the `version` input, it accepts semver ranges.

The `GITHUB_TOKEN` secret must be provided to the action. It is used to query the Github api and download the release files of Swagger UI.

### Example
This Action only generates the Swagger UI.
For example, to deploy it to GitHub Pages another Action is required.
Expand All @@ -30,6 +32,7 @@ Example steps from a workflow to generate and deploy Swagger UI to GitHub Pages:
with:
output: swagger-ui
spec-file: openapi.json
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
Expand Down
63 changes: 63 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@actions/exec": "^1.1.1",
"@actions/http-client": "^2.1.0",
"@actions/io": "^1.1.3",
"@octokit/auth-action": "^4.0.0",
"@octokit/rest": "^19.0.7",
"semver": "^7.5.4"
},
Expand Down
5 changes: 4 additions & 1 deletion src/swagger-ui-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {basename, join} from 'path';
import {Octokit} from '@octokit/rest';
import {exec} from '@actions/exec';
import {satisfies} from 'semver';
import {createActionAuth} from '@octokit/auth-action';

export async function getBasenameInArchive(archive: string): Promise<string> {
let filesList = '';
Expand Down Expand Up @@ -188,7 +189,9 @@ export function invalidSwaggerUiConfig(
export async function getSwaggerUIRelease({
swaggerUIVersion
}: Config): Promise<{tag_name: string; tarball_url: string}> {
const octokit = new Octokit();
const octokit = new Octokit({
authStrategy: createActionAuth
});
const foundReleases = await octokit.paginate(
octokit.rest.repos.listReleases,
{
Expand Down

0 comments on commit 8298031

Please sign in to comment.