Comment Backups #169
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: Comment Backups | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| # 每隔三天下午 17 点 40 | |
| - cron: '40 9 */3 * *' | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v2 | |
| - name: Set up JDK 1.8 | |
| uses: actions/setup-java@v1 | |
| with: | |
| java-version: 1.8 | |
| - name: Cache local Maven repository | |
| uses: actions/cache@v2 | |
| with: | |
| path: ~/.m2/repository | |
| key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-maven- | |
| - name: Set Git Config | |
| run: | | |
| git config --local user.email "action@github.com" | |
| git config --local user.name "GitHub Action" | |
| - name: Check if backup files exist | |
| id: check_files | |
| run: | | |
| PATTERN="/home/runner/work/comment_backups/comment_backups/twikoo-comment*.json" | |
| if find $PATTERN -type f &>/dev/null; then | |
| echo "::set-output name=files_exist::true" | |
| else | |
| echo "::set-output name=files_exist::false" | |
| fi | |
| - name: Delete old backup files in repository | |
| if: steps.check_files.outputs.files_exist == 'true' | |
| run: | | |
| FILES=$(ls /home/runner/work/comment_backups/comment_backups/twikoo-comment*.json) | |
| if [ -n "$FILES" ]; then | |
| git rm $FILES | |
| FILE_NAMES=$(echo "$FILES" | awk -F'/' '{print $NF}') | |
| git commit -m "Delete Old File $FILE_NAMES" || echo "No old backup files to delete" | |
| else | |
| echo "No old backup files to delete" | |
| fi | |
| - name: Build with Maven | |
| env: | |
| PASSWORD: ${{ secrets.PASSWORD }} | |
| TWIKOO_URL: ${{ secrets.TWIKOO_URL }} | |
| run: | | |
| mvn compile exec:java -Dexec.mainClass="cn.imzjw.comment.TwikooBackups" -Dexec.args="${PASSWORD} ${TWIKOO_URL}" | |
| - name: Clean up and commit new file | |
| run: | | |
| git add /home/runner/work/comment_backups/comment_backups/twikoo-comment*.json | |
| git commit -m "Add twikoo-comment-$(date +%Y-%m-%d).json" || echo "No changes to commit" | |
| git push | |
| - name: Delete Workflow Runs | |
| uses: Mattraks/delete-workflow-runs@main | |
| with: | |
| retain_days: 1 | |
| keep_minimum_runs: 1 |