From f34d5735650d5428683b891c2755ffe6cd4711ad Mon Sep 17 00:00:00 2001 From: Leandro Costa Date: Sun, 25 May 2025 19:20:43 -0300 Subject: [PATCH] feat: deploy only if version changed --- .forgejo/workflows/build.yml | 47 ++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/.forgejo/workflows/build.yml b/.forgejo/workflows/build.yml index 8951bbd..3467377 100644 --- a/.forgejo/workflows/build.yml +++ b/.forgejo/workflows/build.yml @@ -46,16 +46,35 @@ jobs: name: lhmask path: lhmask + check-version: + runs-on: ubuntu-latest + outputs: + version_changed: ${{ steps.check.outputs.version_changed }} + steps: + - name: Checkout do repositório + uses: actions/checkout@v4 + with: + fetch-depth: 2 # Necessário para acessar o commit anterior + - name: Verificar mudança de versão no package.json + id: check + run: | + OLD_VERSION=$(git show HEAD^:package.json | jq -r '.version') + NEW_VERSION=$(jq -r '.version' package.json) + echo "Versão anterior: $OLD_VERSION" + echo "Versão atual: $NEW_VERSION" + if [ "$OLD_VERSION" != "$NEW_VERSION" ]; then + echo "version_changed=true" >> "$GITHUB_OUTPUT" + else + echo "version_changed=false" >> "$GITHUB_OUTPUT" + fi + publish-staging: runs-on: docker needs: prepare-package container: image: node:20-alpine - if: github.ref == 'refs/heads/development' || startsWith(github.ref, 'refs/heads/release-no-verify/') + if: needs.check-version.outputs.version_changed == 'true' && (github.ref == 'refs/heads/development' || startsWith(github.ref, 'refs/heads/release-no-verify/')) steps: - - name: Git Clone - uses: actions/checkout@v4 - - name: Download lhmask uses: actions/download-artifact@v3 with: @@ -74,20 +93,18 @@ jobs: needs: prepare-package container: image: node:20-alpine - if: github.ref == 'refs/heads/master' + if: needs.check-version.outputs.version_changed == 'true' && github.ref == 'refs/heads/master' steps: - - name: Git Clone - uses: actions/checkout@v4 + - name: Download lhmask + uses: actions/download-artifact@v3 + with: + path: lhmask + name: lhmask - - name: Prepare Production Package + - name: Publish to NPM (staging) run: | - cp package.json dist/ - cp README.md dist/ + cd lhmask sed -i "s/-dev//g" dist/package.json - - - name: Publish to NPM (production) - run: | - cd dist echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc npm publish env: @@ -97,6 +114,6 @@ jobs: runs-on: docker needs: prepare-package steps: - - name: Publish to NPM (production) + - name: finish run: | echo "OK Done".