Skip to content

Commit da6ede1

Browse files
committed
actionsで作った環境変数をTSで取れてない原因をテスト
1 parent bdc0d0e commit da6ede1

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

.github/workflows/saveToFirestore.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@ jobs:
2626
- name: Install dependencies
2727
run: npm install
2828

29-
# JWTトークンを取得
3029
- name: Generate OIDC Token
3130
id: get-jwt
3231
run: |
33-
echo "JWT_TOKEN=$(curl -s -H 'Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN' \
34-
-H 'Accept: application/json' \
35-
https://vstoken.actions.githubusercontent.com/v1/token?audience=https://firestore-fzxwlwc6iq-an.a.run.app/forecast)" \
36-
>> $GITHUB_ENV
32+
TOKEN=$(curl -s -H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
33+
-H "Accept: application/json" \
34+
https://vstoken.actions.githubusercontent.com/v1/token?audience=https://firestore-fzxwlwc6iq-an.a.run.app/forecast)
35+
echo "JWT_TOKEN=$(echo $TOKEN | jq -r '.value')" >> $GITHUB_ENV
36+
env:
37+
ACTIONS_ID_TOKEN_REQUEST_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3738

3839
# TypeScript ファイルを実行して外部APIを叩き、Firestore APIに送信
3940
- name: Run TypeScript File

src/for-github-actions/fetchData.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ async function fetchData() {
4343
method: "POST",
4444
headers: {
4545
"Content-Type": "application/json",
46-
Auhtorization: `Bearer ${jwtToken}`,
46+
Authorization: `Bearer ${jwtToken}`,
4747
},
4848
body: JSON.stringify(dataToSend),
4949
});
5050
if (!res.ok) {
5151
throw new Error(`Failed to save data: ${res.statusText}`);
5252
}
53-
console.log("successfully saved to Firestore:", res);
53+
console.log("successfully saved to Firestore:", await res.json());
5454
} catch (error) {
5555
console.error("Error saving data:", error);
5656
process.exit(1);

0 commit comments

Comments
 (0)