Skip to content

Commit

Permalink
Merge pull request #34 from arkedge/feature/retry
Browse files Browse the repository at this point in the history
impl retry in client side
  • Loading branch information
sksat authored Jan 22, 2024
2 parents 1cf94b5 + c2663c2 commit 18ea27f
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ inputs:
endpoint:
description: gh-federation lambda endpoint
required: true
retry_max:
description: max retry count
default: "5"
repos:
description: gh-federation repositories
default: ""
Expand All @@ -16,21 +19,32 @@ runs:
- uses: actions/github-script@v6
env:
GH_FEDERATION_ENDPOINT: ${{ inputs.endpoint }}
RETRY_MAX: ${{ inputs.retry_max }}
with:
script: |
const RETRY_MAX = parseInt(process.env["RETRY_MAX"], 10);
const idToken = await core.getIDToken();
const hook = (request, route) => {
const endpoint = request.endpoint.merge(route);
endpoint.headers.authorization = `Bearer ${idToken}`;
return request(endpoint);
};
const { data } = await github.request("POST /token", {
baseUrl: process.env["GH_FEDERATION_ENDPOINT"],
request: { hook },
});
const accessToken = data["token"];
core.setSecret(accessToken);
core.exportVariable("GH_FEDERATION_ACCESS_TOKEN", accessToken);
for (let i = 0; i < RETRY_MAX; ++i) {
try {
const { data } = await github.request("POST /token", {
baseUrl: process.env["GH_FEDERATION_ENDPOINT"],
request: { hook },
});
const accessToken = data["token"];
core.setSecret(accessToken);
core.exportVariable("GH_FEDERATION_ACCESS_TOKEN", accessToken);
break;
} catch (e) {
console.log(`retrying (remain: ${RETRY_MAX - i})...`);
continue;
}
}
- name: Store access token
shell: bash
Expand Down

0 comments on commit 18ea27f

Please sign in to comment.