Код: Выделить всё
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *'
jobs:
refresh-token:
runs-on: [self-hosted, 2-core]
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set Up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Refresh OAuth Token
run: |
curl --request POST \
--url https://xxxx/oauth/token \
--header "Content-Type: application/x-www-form-urlencoded" \
--data "client_id=${{ secrets.CLIENT_ID }}" \
--data "client_secret=${{ secrets.CLIENT_SECRET }}" \
--data "refresh_token=${{ secrets.REFRESH_TOKEN }}" \
--data "grant_type=client_credentials" \
--output response.json
echo "NEW_ACCESS_TOKEN=$(cat response.json | jq -r '.access_token')" >> $GITHUB_ENV
- name: Get GitHub Repository Public Key (for secret encryption)
id: get_public_key
run: |
curl -s -H "Authorization: token ${{ secrets.GH_PAT }}" \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ github.repository }}/actions/secrets/public-key \
> public_key.json
echo "KEY_ID=$(cat public_key.json | jq -r '.key_id')" >> $GITHUB_ENV
echo "PUBLIC_KEY=$(cat public_key.json | jq -r '.key')" >> $GITHUB_ENV
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pynacl
- name: Encrypt the New Access Token
id: encrypt_access_token
run: |
echo "ENCRYPTED_ACCESS_TOKEN=$(python secret_encryptor.py)" >> $GITHUB_ENV
- name: Update the Access Token Secret Using GitHub API
run: |
curl -X PUT -H "Authorization: token ${{ secrets.GH_PAT }}" \
-H "Content-Type: application/json" \
-d '{"encrypted_value":"'"${{ env.ENCRYPTED_ACCESS_TOKEN }}"'","key_id":"'"${{ env.KEY_ID }}"'"}' \
https://api.github.com/repos/${{ github.repository }}/actions/secrets/ACCESS_TOKEN
Подробнее здесь: https://stackoverflow.com/questions/790 ... en-in-gith