diff --git a/.forgejo/workflows/lhisp-oauth-client.yaml b/.forgejo/workflows/lhisp-oauth-client.yaml new file mode 100644 index 0000000..f2dcc0d --- /dev/null +++ b/.forgejo/workflows/lhisp-oauth-client.yaml @@ -0,0 +1,126 @@ +name: CI Pipeline + +on: + push: + branches: + - master + - development + pull_request: + branches: + - development + workflow_dispatch: + +jobs: + build-and-test: + runs-on: docker + container: + image: node:24-alpine + steps: + - name: Git Clone + uses: actions/checkout@v4 + + - name: Restore Node Modules Cache + uses: actions/cache@v3 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + + - name: Install Dependencies + run: npm install + + - name: Build Project + run: npm run build + + - name: Run Tests + run: npm test + + - name: Prepare Package + run: | + cp package.json dist/ + cp README.md dist/ + + - uses: actions/upload-artifact@v3 + name: Upload Artifact + with: + name: dist + path: dist + + check-version: + runs-on: docker + container: + image: node:20-alpine + outputs: + version_changed: ${{ steps.check.outputs.version_changed }} + steps: + - name: Instalando Dependencias + run: | + apk add git jq + - 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-to-npm: + runs-on: docker + needs: [build-and-test, check-version] + container: + image: node:20-alpine + if: needs.check-version.outputs.version_changed == 'true' && (github.ref == 'refs/heads/development' || github.ref == 'refs/heads/master') + steps: + - name: Download Artifact + uses: actions/download-artifact@v3 + with: + path: dist + name: dist + + - name: Ajusta nome do pacote + if: github.ref == 'refs/heads/master' + run: sed -i "s/-dev//g" dist/package.json + + - name: Publish to NPM (staging) + run: | + cd dist + echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc + npm publish + env: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + + publish-to-git: + runs-on: docker + container: + image: node:20-alpine + needs: [build-and-test, check-version] + if: needs.check-version.outputs.version_changed == 'true' && (github.ref == 'refs/heads/development' || github.ref == 'refs/heads/master') + steps: + - name: Download Artifact + uses: actions/download-artifact@v3 + with: + path: dist + name: dist + + - name: Ajusta nome do pacote + if: github.ref == 'refs/heads/master' + run: sed -i "s/-dev//g" dist/package.json + + - name: Publish to Git + run: | + npm config set registry https://git.lhprovedor.com.br/api/packages/leandro/npm/ + npm config set -- '//git.lhprovedor.com.br/api/packages/leandro/npm/:_authToken' "${NPM_TOKEN}" + cd lhmask + npm publish + env: + NPM_TOKEN: ${{ secrets.PACKAGE_PUBLISHER_TOKEN }} diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index 949086f..3ee61eb 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -15,7 +15,7 @@ pipelines: branches: default: <<: *build-and-test - "{development,realease-no-verify/*}": + "{development,release-no-verify/*}": - step: *build-and-test - step: name: Prepare Package