Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create update-tests-snapshot.yml #141

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 138 additions & 0 deletions .github/workflows/update-tests-snapshot.yml
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!
Loading