-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into guibranco-patch-2
- Loading branch information
Showing
1 changed file
with
138 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
name: Update tests Snapshot | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
owner: | ||
description: "The owner of the repository to run" | ||
required: true | ||
default: "guibranco" | ||
repository: | ||
description: "The repository to run" | ||
required: true | ||
default: "gstraccini-bot" | ||
branch: | ||
description: "The branch to run" | ||
required: true | ||
default: "main" | ||
pull_request: | ||
description: "The pull request number" | ||
required: true | ||
default: "-1" | ||
installationId: | ||
description: "The installation id" | ||
required: true | ||
default: "-1" | ||
env: | ||
GHA_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" | ||
|
||
jobs: | ||
prettier: | ||
permissions: write-all | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [18.x] | ||
steps: | ||
- name: Generate a token | ||
id: generate_token | ||
uses: tibdex/github-app-token@v2.1.0 | ||
with: | ||
app_id: ${{ secrets.APP_ID }} | ||
private_key: ${{ secrets.APP_PRIVATE_KEY }} | ||
installation_retrieval_mode: id | ||
installation_retrieval_payload: ${{ github.event.inputs.installationId }} | ||
|
||
- name: Checkout repo | ||
uses: actions/checkout@v4 | ||
with: | ||
repository: "${{ github.event.inputs.owner}}/${{ github.event.inputs.repository }}" | ||
ref: ${{ github.event.inputs.branch }} | ||
token: ${{ steps.generate_token.outputs.token }} | ||
|
||
- name: Setup Node | ||
uses: actions/setup-node@v4.0.2 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: npm | ||
|
||
- name: Install & Test | ||
run: | | ||
npm ci | ||
npm run test --if-present | ||
- name: Run update snapshot | ||
run: | | ||
set -e | ||
echo "$(npm test -- -u)" >> update-snapshot.log | ||
- name: Read update-snapshot.log | ||
uses: guibranco/github-file-reader-action-v2@latest | ||
id: log | ||
with: | ||
path: update-snapshot.log | ||
|
||
- name: Delete update-snapshot.log | ||
run: rm update-snapshot.log 2> /dev/null | ||
|
||
- name: Update PR with comment | ||
uses: mshick/add-pr-comment@v2 | ||
if: ${{ steps.log.outputs.contents != '' }} | ||
with: | ||
repo-token: ${{ steps.generate_token.outputs.token }} | ||
repo-owner: ${{ github.event.inputs.owner }} | ||
repo-name: ${{ github.event.inputs.repository }} | ||
issue: ${{ github.event.inputs.pull_request }} | ||
refresh-message-position: true | ||
allow-repeats: true | ||
message: | | ||
:white_check_mark: [Update test snapshots](${{ env.GHA_URL }}) result: | ||
``` | ||
${{ steps.log.outputs.contents }} | ||
``` | ||
- name: Update PR with comment | ||
uses: mshick/add-pr-comment@v2 | ||
if: ${{ steps.log.outputs.contents == '' }} | ||
with: | ||
repo-token: ${{ steps.generate_token.outputs.token }} | ||
repo-owner: ${{ github.event.inputs.owner }} | ||
repo-name: ${{ github.event.inputs.repository }} | ||
issue: ${{ github.event.inputs.pull_request }} | ||
refresh-message-position: true | ||
allow-repeats: true | ||
message: | | ||
:warning: [Update test snapshots](${{ env.GHA_URL }}) executed! No changes are needed. | ||
- name: Verify Changed files | ||
uses: tj-actions/verify-changed-files@v18 | ||
id: verify-changed-files | ||
|
||
- name: Config git | ||
if: steps.verify-changed-files.outputs.files_changed == 'true' | ||
run: | | ||
git config --local user.email "${{ github.event.inputs.installationId }}+gstraccini[bot]@users.noreply.github.com" | ||
git config --local user.name "gstraccini[bot]" | ||
git config --global --add --bool push.autoSetupRemote true | ||
- name: Commit files | ||
if: steps.verify-changed-files.outputs.files_changed == 'true' | ||
run: | | ||
git add . | ||
git commit -m "Prettier format" | ||
echo "sha1=$(git rev-parse HEAD)" >> $GITHUB_ENV | ||
git push origin ${{ github.event.inputs.branch }} | ||
- name: Update PR with comment | ||
uses: mshick/add-pr-comment@v2 | ||
if: failure() | ||
with: | ||
repo-token: ${{ steps.generate_token.outputs.token }} | ||
repo-owner: ${{ github.event.inputs.owner }} | ||
repo-name: ${{ github.event.inputs.repository }} | ||
issue: ${{ github.event.inputs.pull_request }} | ||
refresh-message-position: true | ||
allow-repeats: true | ||
message: | | ||
:x: [Update test snapshots](${{ env.GHA_URL }}) failed! |