Skip to content

Merge pull request #126 from Sharelter/main #20

Merge pull request #126 from Sharelter/main

Merge pull request #126 from Sharelter/main #20

name: Sync Package Index
# Below is the configuration and variables that you need to set up.
# 1. A environment named `ruyi-sync` is required.
# 2. Some variables are required to be set in the environments:
# - GHO_TOKEN: is described in [docs](https://github.com/ruyisdk/support-matrix/blob/main/assets/docs/ruyi_index_updator.md) as GITHUB_TOKEN (rename due to a same name default var in CI env)
# - PACKAGE_INDEX_OWNER: decide where the pr goes: blank defaults to `ruyisdk`
# - SSH_PRIVATE: A private SSH key of the bot account
#! NOTICE NOTICE NOTICE NOTICE
#! DO NOT MODIFY THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING
#! OR A POTENTIAL PWN ATTACK MAY OCCUR
#! Double check the commit before pushing to avoid any potential security issues
#! NOTICE NOTICE NOTICE NOTICE
on:
push:
workflow_dispatch:
inputs:
makepr:
description: 'Make a PR to sync package index'
required: false
default: 'false'
debuginfo:
description: 'Output Debug'
required: false
default: 'false'
# push: # Uncomment this line to enable push event, but it is not recommended as it may cause unnecessary PRs. Use workflow_dispatch instead.
jobs:
build:
name: Generate and Upload
runs-on: ubuntu-latest
if: ${{ ( github.event_name == 'push' && github.ref == github.ref == 'refs/heads/main' && github.repository_owner == 'ruyisdk' ) || ( github.event_name == 'workflow_dispatch' ) }}
environment: ruyi-sync
env:
GITHUB_TOKEN: ${{ secrets.GHO_TOKEN }}
CACHE_DIR: ~/cache
PACKAGE_INDEX_OWNER: ${{ vars.PACKAGE_INDEX_OWNER }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
cache-dependency-path: '**/requirements*.txt'
- uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE }}
- name: Load Cache
uses: actions/cache@v4
with:
path: |
~/cache
key: ${{ runner.os }}-package-index-sync
- name: Install Dependencies
run: |
sudo apt-get update
pip install -r assets/requirements_ruyinv.txt
- name: Run tool to generate and upload
if: ${{ ( github.event_name == 'workflow_dispatch' && inputs.makepr == 'false' ) }}
run: |
echo "Generate Only" > $RUNNER_TEMP/type.txt
export CI_RUN_ID=${{ github.run_id }}
export CI_RUN_URL=${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
python assets/renew_ruyi_index.py -c assets/config.toml -p . -i $RUNNER_TEMP/cache --log $RUNNER_TEMP/log.txt --warn $RUNNER_TEMP/warn.txt
- name: Run tool to generate and upload and PR
if: ${{ ( github.event_name == 'workflow_dispatch' && inputs.makepr == 'true' ) || ( github.event_name == 'push' ) }}
run: |
echo "Generate and PR" > $RUNNER_TEMP/type.txt
export CI_RUN_ID=${{ github.run_id }}
export CI_RUN_URL=${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
python assets/renew_ruyi_index.py -c assets/config.toml -p . -i $RUNNER_TEMP/cache --log $RUNNER_TEMP/log.txt --warn $RUNNER_TEMP/warn.txt --pr
- name: Output Summary
run: |
echo "# Package Index Sync Report" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "[CI #${{ github.run_number }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) powered by [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }})" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Type: $(cat $RUNNER_TEMP/type.txt)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "CI has built on commit [${{ steps.truecommit.outputs.shortid }}](${{ github.server_url }}/${{ github.repository }}/commit/${{ steps.truecommit.outputs.longid }}). The commit message is shown below." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`text" >> $GITHUB_STEP_SUMMARY
echo "$(git log -1)" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "## Warn Log" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`text" >> $GITHUB_STEP_SUMMARY
cat $RUNNER_TEMP/warn.txt >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "## Build Log" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "<details><summary>Click to expand</summary>" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`text" >> $GITHUB_STEP_SUMMARY
cat $RUNNER_TEMP/log.txt >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "</details>" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
- name: Output Debug Info
if: ${{ github.event_name == 'workflow_dispatch' && inputs.debuginfo == 'true' }}
run: |
echo "## Debug Info" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`json" >> $GITHUB_STEP_SUMMARY
echo "${{ toJSON( github ) }}" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY