diff --git a/.github/workflows/auto-pr-comment.yml b/.github/workflows/auto-pr-comment.yml new file mode 100644 index 0000000..27ca08e --- /dev/null +++ b/.github/workflows/auto-pr-comment.yml @@ -0,0 +1,223 @@ +name: 🤖 PR Commands + +on: + issue_comment: + types: [created] + +jobs: + snapshot: + name: 🚚 Snapshot + if: github.event.issue.pull_request && contains(github.event.comment.body, '/snapshot') + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - name: Get Action URL + id: action-url + run: echo "url=https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" >> $GITHUB_OUTPUT + + - name: Create comment + uses: peter-evans/create-or-update-comment@v4 + with: + comment-id: ${{ github.event.comment.id }} + edit-mode: replace + body: | + **🚚 Snapshot Version in Progress...** + + [Check out the release on GitHub ↗︎](${{ steps.action-url.outputs.url }}) + + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: ./.github/workflows/actions/setup + + - name: get-npm-version + id: package-version + uses: martinbeentjes/npm-get-version-action@v1.3.1 + with: + path: packages/core + + - name: Get Last Commit SHA + id: last-commit + run: | + COMMITS_URL="https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.issue.number }}/commits" + LAST_COMMIT_SHA=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" $COMMITS_URL | jq -r '.[-1].sha') + echo "sha=$LAST_COMMIT_SHA" >> $GITHUB_OUTPUT + + - name: Shorten Commit Sha + id: short-sha + run: echo "value=$(git rev-parse --short ${{ steps.last-commit.outputs.sha }})" >> $GITHUB_OUTPUT + + - name: Create version + id: set-version + run: echo "version=${{ steps.package-version.outputs.current-version}}-snapshot.${{ github.event.issue.number }}-${{ steps.short-sha.outputs.value }}" >> $GITHUB_OUTPUT + + - name: Print version + run: echo "${{steps.set-version.outputs.version}}" + + - uses: ./.github/workflows/actions/release-setup + with: + token: ${{ secrets.GITHUB_TOKEN }} + npm-token: ${{ secrets.NPM_PUBLISH_TOKEN }} + + - name: Define version + run: npx nx release version --git-commit=false --git-tag=false --preid=snapshot --specifier=${{steps.set-version.outputs.version}} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Build + run: npx nx run-many -t build --projects=tag:scope:release + + - name: Pre-Publish + run: npx nx run pre-publish + + - name: Publish + run: npx nx release publish --tag=snapshot + + - name: Create comment + if: success() + uses: peter-evans/create-or-update-comment@v4 + with: + comment-id: ${{ github.event.comment.id }} + edit-mode: replace + body: | + **🚀 Snapshot Version Released!** + + Version: `${{ steps.set-version.outputs.version }}` + + [Check out the release on GitHub ↗︎](${{ steps.action-url.outputs.url }}) + + - name: Create comment + if: failure() + uses: peter-evans/create-or-update-comment@v4 + with: + comment-id: ${{ github.event.comment.id }} + edit-mode: replace + body: | + ** 💩 Snapshot Version Failed!** + + Version: `${{ steps.set-version.outputs.version }}` + + [Check out the release on GitHub ↗︎](${{ steps.action-url.outputs.url }}) + + - name: Git Reset + run: git reset --hard + + visual: + name: 📸 Create Base Image + if: github.event.issue.pull_request && contains(github.event.comment.body, '/create-base-image') + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - name: Get Action URL + id: action-url + run: echo "url=https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" >> $GITHUB_OUTPUT + + - name: Check for /create-base-image command + uses: actions/github-script@v5 + id: command + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + result-encoding: string + script: | + const comment = context.payload.comment.body.trim(); + const regex = /\/create-base-image(?:\s+(.*))?/; + if (regex.test(comment)) { + const match = comment.match(regex); + const imageName = match[1] ? match[1].trim() : ''; + console.log(`Detected /create-base-image command with argument: ${imageName}`); + // Set the output variable + return imageName; + } + return 'all' + + - name: Get result + run: echo "${{ steps.command.outputs.result }}" + + - name: Create comment + uses: peter-evans/create-or-update-comment@v4 + with: + comment-id: ${{ github.event.comment.id }} + edit-mode: replace + body: | + **📸 Create Base Image in Progress...** + + Specs: ${{ steps.command.outputs.result }} + + [Check out the release on GitHub ↗︎](${{ steps.action-url.outputs.url }}) + + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: ./.github/workflows/actions/e2e-build + with: + build: true + token: ${{ secrets.GITHUB_TOKEN }} + + - uses: ./.github/workflows/actions/e2e-setup + + - name: Run All Cypress + if: steps.command.outputs.result == 'all' + uses: cypress-io/github-action@v6 + with: + start: node ./web-server.js + wait-on: 'http://localhost:3333' + working-directory: e2e + install: false + browser: chrome + env: type=base + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Run Cypress by files + if: steps.command.outputs.result == 'all' + uses: cypress-io/github-action@v6 + with: + start: node ./web-server.js + wait-on: 'http://localhost:3333' + working-directory: e2e + install: false + browser: chrome + env: type=base + spec: ${{ steps.command.outputs.result }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Upload snapshots + if: failure() + uses: actions/upload-artifact@v4 + with: + name: cypress-snapshots + path: e2e/cypress/snapshots + + - name: Commit base images + uses: EndBug/add-and-commit@v9 + with: + message: 'update base images' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Create comment + if: success() + uses: peter-evans/create-or-update-comment@v4 + with: + comment-id: ${{ github.event.comment.id }} + edit-mode: replace + body: | + **📸 Create Base Image finished!** + + Specs: ${{ steps.command.outputs.result }} + + [Check out the release on GitHub ↗︎](${{ steps.action-url.outputs.url }}) + + - name: Create comment + if: failure() + uses: peter-evans/create-or-update-comment@v4 + with: + comment-id: ${{ github.event.comment.id }} + edit-mode: replace + body: | + ** 💩 Create Base Image Failed!** + + Specs: ${{ steps.command.outputs.result }} + + [Check out the release on GitHub ↗︎](${{ steps.action-url.outputs.url }}) diff --git a/.github/workflows/create-base.yml b/.github/workflows/create-base.yml deleted file mode 100644 index 3b112eb..0000000 --- a/.github/workflows/create-base.yml +++ /dev/null @@ -1,47 +0,0 @@ -name: 📸 Create Base Image by File - -on: - issue_comment: - types: [created] - -jobs: - CreateSnapshot: - if: github.event.issue.pull_request && contains(github.event.comment.body, '/create-base-image') - runs-on: ubuntu-latest - timeout-minutes: 15 - steps: - - name: Get Action URL - id: action-url - run: echo "url=https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" >> $GITHUB_OUTPUT - - - name: Check for /create-base-image command - uses: actions/github-script@v5 - id: command - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - result-encoding: string - script: | - const comment = context.payload.comment.body.trim(); - const regex = /\/create-base-image(?:\s+(.*))?/; - if (regex.test(comment)) { - const match = comment.match(regex); - const imageName = match[1] ? match[1].trim() : ''; - console.log(`Detected /create-base-image command with argument: ${imageName}`); - // Set the output variable - return imageName; - } - return '' - - - name: Get result - run: echo "${{ steps.command.outputs.result }}" - - # - name: Create comment - # uses: peter-evans/create-or-update-comment@v4 - # with: - # comment-id: ${{ github.event.comment.id }} - # edit-mode: replace - # body: | - # **📸 Create Base Image in Progress...** - - # [Check out the release on GitHub ↗︎](${{ steps.action-url.outputs.url }}) - diff --git a/.github/workflows/snapshot.yml b/.github/workflows/snapshot.yml deleted file mode 100644 index ae5a9bc..0000000 --- a/.github/workflows/snapshot.yml +++ /dev/null @@ -1,102 +0,0 @@ -name: 🚚 Snapshot - -on: - issue_comment: - types: [created] - -jobs: - CreateSnapshot: - if: github.event.issue.pull_request && contains(github.event.comment.body, '/snapshot') - runs-on: ubuntu-latest - timeout-minutes: 15 - steps: - - name: Get Action URL - id: action-url - run: echo "url=https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" >> $GITHUB_OUTPUT - - - name: Create comment - uses: peter-evans/create-or-update-comment@v4 - with: - comment-id: ${{ github.event.comment.id }} - edit-mode: replace - body: | - **🚚 Snapshot Version in Progress...** - - [Check out the release on GitHub ↗︎](${{ steps.action-url.outputs.url }}) - - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - uses: ./.github/workflows/actions/setup - - - name: get-npm-version - id: package-version - uses: martinbeentjes/npm-get-version-action@v1.3.1 - with: - path: packages/core - - - name: Get Last Commit SHA - id: last-commit - run: | - COMMITS_URL="https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.issue.number }}/commits" - LAST_COMMIT_SHA=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" $COMMITS_URL | jq -r '.[-1].sha') - echo "sha=$LAST_COMMIT_SHA" >> $GITHUB_OUTPUT - - - name: Shorten Commit Sha - id: short-sha - run: echo "value=$(git rev-parse --short ${{ steps.last-commit.outputs.sha }})" >> $GITHUB_OUTPUT - - - name: Create version - id: set-version - run: echo "version=${{ steps.package-version.outputs.current-version}}-snapshot.${{ github.event.issue.number }}-${{ steps.short-sha.outputs.value }}" >> $GITHUB_OUTPUT - - - name: Print version - run: echo "${{steps.set-version.outputs.version}}" - - - uses: ./.github/workflows/actions/release-setup - with: - token: ${{ secrets.GITHUB_TOKEN }} - npm-token: ${{ secrets.NPM_PUBLISH_TOKEN }} - - - name: Define version - run: npx nx release version --git-commit=false --git-tag=false --preid=snapshot --specifier=${{steps.set-version.outputs.version}} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Build - run: npx nx run-many -t build --projects=tag:scope:release - - - name: Pre-Publish - run: npx nx run pre-publish - - - name: Publish - run: npx nx release publish --tag=snapshot - - - name: Create comment - if: success() - uses: peter-evans/create-or-update-comment@v4 - with: - comment-id: ${{ github.event.comment.id }} - edit-mode: replace - body: | - **🚀 Snapshot Version Released!** - - Version: `${{ steps.set-version.outputs.version }}` - - [Check out the release on GitHub ↗︎](${{ steps.action-url.outputs.url }}) - - - name: Create comment - if: failure() - uses: peter-evans/create-or-update-comment@v4 - with: - comment-id: ${{ github.event.comment.id }} - edit-mode: replace - body: | - ** 💩 Snapshot Version Failed!** - - Version: `${{ steps.set-version.outputs.version }}` - - [Check out the release on GitHub ↗︎](${{ steps.action-url.outputs.url }}) - - - name: Git Reset - run: git reset --hard diff --git a/.github/workflows/visual-base-file.yml b/.github/workflows/visual-base-file.yml index 03e8ce1..efd6b8d 100644 --- a/.github/workflows/visual-base-file.yml +++ b/.github/workflows/visual-base-file.yml @@ -47,7 +47,6 @@ jobs: path: e2e/cypress/snapshots - name: Commit base images - if: failure() uses: EndBug/add-and-commit@v9 with: message: 'update base images' diff --git a/.github/workflows/visual-base.yml b/.github/workflows/visual-base.yml index 1b05a9f..477ae31 100644 --- a/.github/workflows/visual-base.yml +++ b/.github/workflows/visual-base.yml @@ -42,7 +42,6 @@ jobs: path: e2e/cypress/snapshots - name: Commit base images - if: failure() uses: EndBug/add-and-commit@v9 with: message: 'update base images'