Skip to content

Commit

Permalink
Use @actions/core to get the token
Browse files Browse the repository at this point in the history
  • Loading branch information
kb-1000 committed Nov 6, 2023
1 parent f8fc21c commit 603ad07
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,18 @@ jobs:
arguments: --stacktrace --parallel clean build
- name: Get Id Token
uses: actions/github-script@v6
id: idtoken
with:
script: |
let id_token = await core.getIDToken("https://mc.pswg.dev")
core.setOutput('id_token', id_token)
- name: upload
if: always() && github.ref == 'refs/heads/master' && (steps.gradle.outcome == 'success' || steps.gradle.outcome == 'failure')
continue-on-error: true
run: |
mkdir -p projects/pswg/build/libs
cd projects/pswg/build/libs
pip install -r ../../../../scripts/requirements.txt
python ../../../../scripts/upload_dev.py --result ${{ steps.gradle.outcome }} --webhook ${{ secrets.DISCORD_DEV_FEED_WEBHOOK }} --serverupdate ${{ secrets.SERVER_UPDATER }}
python ../../../../scripts/upload_dev.py --token ${{ steps.idtoken.outputs.id_token }} --result ${{ steps.gradle.outcome }} --webhook ${{ secrets.DISCORD_DEV_FEED_WEBHOOK }} --serverupdate ${{ secrets.SERVER_UPDATER }}
env:
BUILD_NUMBER: ${{ github.run_number }}
14 changes: 4 additions & 10 deletions scripts/upload_dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
parser.add_argument("--result", type=str, default="success")
parser.add_argument("--webhook", type=str, action="append")
parser.add_argument("--serverupdate", type=str, action="append")
parser.add_argument("--token", type=str, default=None)

args = parser.parse_args()

Expand Down Expand Up @@ -40,20 +41,13 @@
print("discord response:", resp.text)
if args.serverupdate:
for url in args.serverupdate:
with requests.post(
f"{os.environ['ACTIONS_ID_TOKEN_REQUEST_URL']}&{urllib.parse.urlencode({'audience': 'https://mc.pswg.dev'})}",
headers={
"Authorization": f"Bearer {os.environ['ACTIONS_ID_TOKEN_REQUEST_TOKEN']}"
},
) as resp:
print(resp.url)
resp.raise_for_status()
token = resp.json()["value"]
with open(file, "rb") as fp:
with requests.post(
url,
files={"file": fp},
headers={"Authorization": f"Bearer {token}"},
headers={"Authorization": f"Bearer {args.token}"}
if args.token
else {},
) as resp:
resp.raise_for_status()
print("server updater response:", resp.text)
Expand Down

0 comments on commit 603ad07

Please sign in to comment.