diff --git a/.github/workflows/snapshot.yml b/.github/workflows/snapshot.yml index e2f5504..d6c07bb 100644 --- a/.github/workflows/snapshot.yml +++ b/.github/workflows/snapshot.yml @@ -1,6 +1,14 @@ name: 📸 on: + push: + branches: + - main + paths-ignore: + - '**.md' + pull_request: + paths-ignore: + - '**.md' schedule: # Every 10:42 JST # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule @@ -12,6 +20,16 @@ jobs: runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 + - name: Prepare Git user + run: | + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + - name: Prepare Git branch + id: prepare-branch + run: | + started_at="$(date +%Y%m%d-%H%M%S)" + git switch -c "${{ github.sha }}-${started_at}" + echo started_at="$started_at" | tee -a "$GITHUB_OUTPUT" - name: Set up Go uses: actions/setup-go@v5 with: @@ -23,3 +41,19 @@ jobs: version: '3.36.0' # selfup {"extract":"\\d\\.\\d+\\.\\d+","replacer":["task", "--version"], "nth": 3} - run: | task snapshot | tee -a snapshot.txt + - name: Update related CI dependencies + run: | + git diff-index --quiet HEAD || git commit -m 'Update snapshots' snapshot.txt + - name: Count added commits + id: count-commits + run: | + count="$(git rev-list --count origin/${{ github.event.repository.default_branch }}..)" + echo "count=${count}" | tee -a "$GITHUB_OUTPUT" + - run: git push origin '${{ steps.prepare-branch.outputs.started_at }}' + if: ${{ github.event_name != 'pull_request' }} && (steps.count-commits.outputs.count > 0) + - name: Create PR + if: ${{ github.event_name != 'pull_request' }} && (steps.count-commits.outputs.count > 0) + env: + GITHUB_TOKEN: ${{ github.token }} + run: | + gh pr create --base '${{ github.event.repository.default_branch }}' --title 'Update snapshots'