CI: Add CI for package index sync #2
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Sync Package Index | |
on: | |
pull_request: | |
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 | |
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/ssh-agent@v0.9.0 | |
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 ) || github.event_name != 'pull_request' || ( github.event_name == 'pull_request' && github.event.pull_request.merged == false ) }} | |
run: | | |
echo "Generate Only" > $RUNNER_TEMP/type.txt | |
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 == 'pull_request' && github.event.pull_request.merged == true ) }} | |
run: | | |
echo "Generate and PR" > $RUNNER_TEMP/type.txt | |
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 }} | |
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 |