在拉取配置时校验版本号 #9
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: Sync Config to Website | |
| on: | |
| push: | |
| branches: [ main ] | |
| paths: | |
| - "core/src/main/kotlin/io/github/autotweaker/core/data/settings/**" | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| jobs: | |
| sync-config: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| - name: Setup Gradle | |
| uses: gradle/actions/setup-gradle@v6 | |
| - name: Build project | |
| run: ./gradlew build | |
| - name: Serialize config | |
| run: ./gradlew :core:serializeConfig | |
| - name: Setup SSH key | |
| run: | | |
| mkdir -p ~/.ssh | |
| echo "${{ secrets.WEBSITE_DEPLOY_KEY }}" > ~/.ssh/deploy_key | |
| chmod 600 ~/.ssh/deploy_key | |
| ssh-keyscan -t ed25519 github.com >> ~/.ssh/known_hosts | |
| env: | |
| GIT_SSH_COMMAND: "ssh -i ~/.ssh/deploy_key" | |
| - name: Clone website repository | |
| run: | | |
| mkdir -p .temp | |
| git clone git@github.com:AutoTweaker/website.git .temp/website-repo | |
| cd .temp/website-repo | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| env: | |
| GIT_SSH_COMMAND: "ssh -i ~/.ssh/deploy_key" | |
| - name: Extract SETTINGS_VERSION | |
| run: | | |
| SETTINGS_VERSION=$(grep -oP 'const val SETTINGS_VERSION = "\K[^"]+' \ | |
| core/src/main/kotlin/io/github/autotweaker/core/data/settings/SerializeConfig.kt) | |
| echo "SETTINGS_VERSION=$SETTINGS_VERSION" >> "$GITHUB_ENV" | |
| - name: Update index.json version | |
| run: | | |
| cd .temp/website-repo | |
| jq '.[0].version = "${{ env.SETTINGS_VERSION }}"' index.json > index.json.tmp | |
| mv index.json.tmp index.json | |
| - name: Copy config to website | |
| run: | | |
| mkdir -p .temp/website-repo/default_config | |
| cp .temp/default_config/AppConfig.json .temp/website-repo/default_config/AppConfig.json | |
| - name: Commit and push changes | |
| run: | | |
| cd .temp/website-repo | |
| git add default_config/AppConfig.json | |
| if git diff --staged --quiet; then | |
| echo "No changes to commit" | |
| else | |
| git commit -m "Update config from AutoTweaker/core" | |
| git push origin main | |
| fi | |
| env: | |
| GIT_SSH_COMMAND: "ssh -i ~/.ssh/deploy_key" |