Repository navigation
config-source-update #191
This file contains hidden or 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: Auto Update Config | |
| permissions: | |
| contents: write | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| debug_enabled: | |
| type: boolean | |
| description: "Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)" | |
| required: false | |
| default: false | |
| repository_dispatch: | |
| types: [config-source-update, patch-source-update] | |
| jobs: | |
| main: | |
| runs-on: ubuntu-latest | |
| env: | |
| SOLARIS_API_VERSION: v1 | |
| SOLARIS_API_URL: https://api.seerapi.com | |
| SOLARIS_DATA_SOURCE: https://github.com/SeerAPI/config-sources.git | |
| SOLARIS_PATCH_SOURCE: https://github.com/SeerAPI/patch-sources.git | |
| BASE_OUTPUT_DIR: data | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.10" | |
| - name: Set up uv | |
| uses: astral-sh/setup-uv@v7 | |
| - name: Install solaris | |
| run: uv tool install --force --upgrade seerapi-solaris | |
| - name: Setup tmate session | |
| uses: mxschmitt/action-tmate@v3 | |
| if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }} | |
| - name: Clone config sources | |
| run: | | |
| git clone ${{ env.SOLARIS_DATA_SOURCE }} source | |
| git clone ${{ env.SOLARIS_PATCH_SOURCE }} patch-sources | |
| mkdir -p source/patch | |
| mv patch-sources/patches/* source/patch | |
| - name: Analyze config | |
| run: | | |
| solaris analyze data --base-output-dir ${{ env.BASE_OUTPUT_DIR }} -o data --json-format split \ | |
| --base-json-url https://api.seerapi.com/v1 \ | |
| --db-url sqlite:///seerapi-data.sqlite \ | |
| -m all --output-named-data | |
| solaris analyze data --base-output-dir ${{ env.BASE_OUTPUT_DIR }} -o sharded_data --json-format sharded \ | |
| --base-json-url https://api.seerapi.com/v1 \ | |
| -m json --output-named-data | |
| solaris analyze schemas --base-output-dir ${{ env.BASE_OUTPUT_DIR }} -o schemas \ | |
| --base-url https://api.seerapi.com/v1/schemas --output-named-data | |
| openapi_desc=$(cat .github/workflows/openapi-desc.md) | |
| detail_version="1.0.0" | |
| solaris analyze openapi --base-output-dir ${{ env.BASE_OUTPUT_DIR }} -o openapi.json \ | |
| --description "$openapi_desc" --detail-version "$detail_version" --output-named-data | |
| - name: Commit and push changes | |
| id: commit | |
| run: | | |
| git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
| git config --local user.name "github-actions[bot]" | |
| git add data | |
| timestamp=$(TZ='Asia/Shanghai' date '+%Y-%m-%d %H:%M:%S CST') | |
| git diff --staged --quiet || git commit -m "Auto update config $timestamp" | |
| git push | |
| echo "timestamp=$timestamp" >> $GITHUB_OUTPUT | |
| # - name: Push to cnb.cool Git Repository | |
| # run: | | |
| # # 配置 cnb.cool 远程仓库 | |
| # git remote add cnb https://cnb:${{ secrets.CNB_TOKEN }}@cnb.cool/${{ secrets.CNB_REPO_PATH }}.git || true | |
| # git remote set-url cnb https://cnb:${{ secrets.CNB_TOKEN }}@cnb.cool/${{ secrets.CNB_REPO_PATH }}.git | |
| # | |
| # # 推送到 cnb.cool 仓库 | |
| # git push cnb main --force | |
| - name: Create archives for release | |
| run: | | |
| set -eux | |
| mkdir -p artifacts | |
| # Package schemas (path: $BASE_OUTPUT_DIR/schemas) | |
| if [ -d "${{ env.BASE_OUTPUT_DIR }}/${{ env.SOLARIS_API_VERSION }}/schemas" ]; then | |
| tar -czf artifacts/schemas.tar.gz -C "${{ env.BASE_OUTPUT_DIR }}/${{ env.SOLARIS_API_VERSION }}" schemas | |
| else | |
| echo "Warning: ${BASE_OUTPUT_DIR}/schemas not found" | |
| fi | |
| # Package data (path: $BASE_OUTPUT_DIR/data) | |
| if [ -d "${{ env.BASE_OUTPUT_DIR }}/${{ env.SOLARIS_API_VERSION }}/data" ]; then | |
| tar -czf artifacts/data.tar.gz -C "${{ env.BASE_OUTPUT_DIR }}/${{ env.SOLARIS_API_VERSION }}" data | |
| else | |
| echo "Warning: ${BASE_OUTPUT_DIR}/data not found" | |
| fi | |
| # Package sharded_data (path: $BASE_OUTPUT_DIR/sharded_data) | |
| if [ -d "${{ env.BASE_OUTPUT_DIR }}/${{ env.SOLARIS_API_VERSION }}/sharded_data" ]; then | |
| tar -czf artifacts/sharded_data.tar.gz -C "${{ env.BASE_OUTPUT_DIR }}/${{ env.SOLARIS_API_VERSION }}" sharded_data | |
| else | |
| echo "Warning: ${BASE_OUTPUT_DIR}/sharded_data not found" | |
| fi | |
| ls -lah artifacts || true | |
| - name: Generate database checksum | |
| id: db_checksum | |
| run: | | |
| # 生成 SHA256 校验和文件 | |
| sha256sum seerapi-data.sqlite > seerapi-data.sqlite.sha256 | |
| # 显示校验和信息 | |
| echo "=== 数据库文件 SHA256 校验和 ===" | |
| cat seerapi-data.sqlite.sha256 | |
| # 将校验和传递到下一个step | |
| echo "sha256=$(cat seerapi-data.sqlite.sha256)" >> $GITHUB_OUTPUT | |
| - name: Upload data and archives to release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: latest | |
| name: Data Update - ${{ steps.commit.outputs.timestamp }} | |
| body: | | |
| 最新的 SeerAPI 数据库和打包数据 | |
| 更新时间: ${{ steps.commit.outputs.timestamp }} | |
| 上传内容: | |
| - schemas 压缩包: artifacts/schemas.tar.gz | |
| - data 压缩包: artifacts/data.tar.gz | |
| - sharded_data 压缩包: artifacts/sharded_data.tar.gz | |
| - 数据库: seerapi-data.sqlite | |
| - 数据库校验和: seerapi-data.sqlite.sha256 | |
| SHA256 校验和: ${{ steps.db_checksum.outputs.sha256 }} | |
| **注意,该效验和仅用于验证数据库文件的完整性,不能用于验证数据库内容是否有更新** | |
| files: | | |
| artifacts/schemas.tar.gz | |
| artifacts/data.tar.gz | |
| artifacts/sharded_data.tar.gz | |
| seerapi-data.sqlite | |
| seerapi-data.sqlite.sha256 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| prerelease: false | |
| draft: false | |
| make_latest: true | |
| fail_on_unmatched_files: true | |
| - name: Repository Dispatch | |
| uses: peter-evans/repository-dispatch@v4 | |
| with: | |
| token: ${{ secrets.PAT }} | |
| repository: seerapi/eo-seerapi | |
| event-type: api-data-updated |