From 8b8243d31e538757730464ed15946bf4e52f07cd Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Sat, 5 Oct 2024 23:56:31 -0300 Subject: [PATCH 1/5] feat: enforce semver changes --- .github/workflows/pullRequest.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/.github/workflows/pullRequest.yml b/.github/workflows/pullRequest.yml index 31f87d3..01b7f5d 100644 --- a/.github/workflows/pullRequest.yml +++ b/.github/workflows/pullRequest.yml @@ -112,3 +112,27 @@ jobs: - name: Find dead code run: yarn deadCode + + version-check: + name: Check package version + runs-on: ubuntu-latest + steps: + - name: Checkout PR + uses: actions/checkout@v3 + + - name: Checkout main + uses: actions/checkout@v3 + with: + ref: main + path: main + + - name: Compare versions + run: | + PR_VERSION=$(node -p "require('./package.json').version") + MAIN_VERSION=$(node -p "require('./main/package.json').version") + if [ "$PR_VERSION" = "$MAIN_VERSION" ]; then + echo "Error: Package version has not been updated" + exit 1 + else + echo "Package version has been updated" + fi From dc7f6f6f427d42e45adb5b63b861a96b97866a61 Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Sat, 5 Oct 2024 23:57:07 -0300 Subject: [PATCH 2/5] feat: only checkout latest commit --- .github/workflows/pullRequest.yml | 11 +++++++++++ .github/workflows/release.yml | 11 ++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pullRequest.yml b/.github/workflows/pullRequest.yml index 01b7f5d..c604fb5 100644 --- a/.github/workflows/pullRequest.yml +++ b/.github/workflows/pullRequest.yml @@ -9,6 +9,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + with: + fetch-depth: 1 - name: Use Node.js 18.x uses: actions/setup-node@v3 @@ -39,6 +41,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + with: + fetch-depth: 1 - name: Use Node.js 18.x uses: actions/setup-node@v3 @@ -70,6 +74,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + with: + fetch-depth: 1 - name: Use Node.js 18.x uses: actions/setup-node@v3 @@ -95,6 +101,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + with: + fetch-depth: 1 - name: Use Node.js 18.x uses: actions/setup-node@v3 @@ -119,12 +127,15 @@ jobs: steps: - name: Checkout PR uses: actions/checkout@v3 + with: + fetch-depth: 1 - name: Checkout main uses: actions/checkout@v3 with: ref: main path: main + fetch-depth: 1 - name: Compare versions run: | diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 72ef5a1..16307e2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,6 +11,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + with: + fetch-depth: 1 - name: Use Node.js 16.x uses: actions/setup-node@v3 @@ -41,6 +43,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + with: + fetch-depth: 1 - name: Use Node.js 16.x uses: actions/setup-node@v3 @@ -72,6 +76,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + with: + fetch-depth: 1 - name: Use Node.js 16.x uses: actions/setup-node@v3 @@ -97,6 +103,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + with: + fetch-depth: 1 - name: Use Node.js 16.x uses: actions/setup-node@v3 @@ -122,6 +130,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + with: + fetch-depth: 1 - name: Use Node.js 16.x uses: actions/setup-node@v3 @@ -148,4 +158,3 @@ jobs: github_token: ${{ secrets.GITHUB_TOKEN }} publish_command: npm publish --access public generate_release_notes: true - From b80ef6d3ee6114ce43bbe4e15cec27f875edb4d7 Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Sat, 5 Oct 2024 23:59:37 -0300 Subject: [PATCH 3/5] feat: also check if new version is bigger than the current --- .github/workflows/pullRequest.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pullRequest.yml b/.github/workflows/pullRequest.yml index c604fb5..6c7fd13 100644 --- a/.github/workflows/pullRequest.yml +++ b/.github/workflows/pullRequest.yml @@ -144,6 +144,9 @@ jobs: if [ "$PR_VERSION" = "$MAIN_VERSION" ]; then echo "Error: Package version has not been updated" exit 1 + elif ! npx semver -r ">$MAIN_VERSION" "$PR_VERSION" > /dev/null; then + echo "Error: New version ($PR_VERSION) is not greater than current version ($MAIN_VERSION)" + exit 1 else - echo "Package version has been updated" + echo "Package version has been updated correctly" fi From 14adb795712c4410e8152ea168f5a7bb8654847d Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Sun, 6 Oct 2024 00:02:54 -0300 Subject: [PATCH 4/5] feat: append comment with error to the PR --- .github/workflows/pullRequest.yml | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pullRequest.yml b/.github/workflows/pullRequest.yml index 6c7fd13..48e5f26 100644 --- a/.github/workflows/pullRequest.yml +++ b/.github/workflows/pullRequest.yml @@ -138,15 +138,29 @@ jobs: fetch-depth: 1 - name: Compare versions + id: version_check run: | PR_VERSION=$(node -p "require('./package.json').version") MAIN_VERSION=$(node -p "require('./main/package.json').version") if [ "$PR_VERSION" = "$MAIN_VERSION" ]; then - echo "Error: Package version has not been updated" + echo "ERROR_MESSAGE=Error: Package version has not been updated" >> $GITHUB_OUTPUT exit 1 elif ! npx semver -r ">$MAIN_VERSION" "$PR_VERSION" > /dev/null; then - echo "Error: New version ($PR_VERSION) is not greater than current version ($MAIN_VERSION)" + echo "ERROR_MESSAGE=Error: New version ($PR_VERSION) is not greater than current version ($MAIN_VERSION)" >> $GITHUB_OUTPUT exit 1 else echo "Package version has been updated correctly" fi + + - name: Comment PR + if: failure() + uses: actions/github-script@v6 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: '${{ steps.version_check.outputs.ERROR_MESSAGE }}' + }) From 72632e44260166a1fdf6128a4c089faf02eebc6b Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Sun, 6 Oct 2024 00:05:35 -0300 Subject: [PATCH 5/5] chore: increase patch version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 18cdfdb..4c978c4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@arthurgeron/eslint-plugin-react-usememo", - "version": "2.4.1", + "version": "2.4.2", "description": "", "main": "dist/index.js", "author": "Stefano J. Attardi & Arthur Geron