feat: deploy only if version changed
Some checks are pending
CI Pipeline / check-version (push) Waiting to run
CI Pipeline / build-and-test (push) Successful in 1m11s
CI Pipeline / publish-staging (push) Has been skipped
CI Pipeline / publish-production (push) Has been skipped
CI Pipeline / finish-deploy (push) Successful in 1s

This commit is contained in:
Leandro Costa 2025-05-25 19:20:43 -03:00
parent 331cd30754
commit f34d573565

View file

@ -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".