diff --git a/.forgejo/actions/check-package-version/action.yaml b/.forgejo/actions/check-package-version/action.yaml index 85335ce..8be5a12 100644 --- a/.forgejo/actions/check-package-version/action.yaml +++ b/.forgejo/actions/check-package-version/action.yaml @@ -5,6 +5,7 @@ inputs: package_json_path: description: Path to package.json file default: package.json + required: false outputs: version_changed: description: "Whether the version changed" @@ -42,3 +43,4 @@ runs: fi echo "package_version=$NEW_VERSION" >> "$GITHUB_OUTPUT" + echo "PACKAGE_VERSION=$NEW_VERSION" >> "$GITHUB_ENV" diff --git a/.forgejo/actions/publish-npm-package/action.yaml b/.forgejo/actions/publish-npm-package/action.yaml new file mode 100644 index 0000000..29a47c0 --- /dev/null +++ b/.forgejo/actions/publish-npm-package/action.yaml @@ -0,0 +1,92 @@ +name: Publish Package to NPM Repository +description: This action will verify if the package exists on the repository and publish to it if needed + +inputs: + npm_token: + description: NPM_TOKEN to access the repository + required: true + git_token: + description: Token to publish packages + required: true + git_username: + description: user name that will hold the packages + required: true + git_url: + description: user name that will hold the packages + required: true + artifact_folder_name: + description: The Artifact to be downloaded + default: dist + required: false +outputs: + version_changed: + description: "Whether the version changed" + value: ${{ steps.check.outputs.version_changed }} + package_version: + description: "Current version from package.json" + value: ${{ steps.check.outputs.package_version }} + +runs: + using: composite + steps: + - name: Instalando Dependencias + shell: sh + run: apk add git jq sed + + - name: Download Artifact + uses: actions/download-artifact@v3 + with: + path: ${{ inputs.artifact_folder_name }} + name: dist + + - name: Ajusta nome do pacote + if: github.ref == 'refs/heads/master' + shell: sh + run: sed -i "s/-dev//g" dist/package.json + + - name: LĂȘ o nome do pacote + shell: sh + run: | + PACKAGE_NAME=$(jq -r .name dist/package.json) + PACKAGE_VERSION=$(jq -r .version dist/package.json) + + echo "Package Name: $PACKAGE_NAME" + echo "Package Version: $PACKAGE_VERSION" + + echo "PACKAGE_NAME=$PACKAGE_NAME" >> "$GITHUB_ENV" + echo "PACKAGE_VERSION=$PACKAGE_VERSION" >> "$GITHUB_ENV" + + - name: Publish to NPM.js + shell: sh + run: | + cd dist + echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc + + if npm view "${PACKAGE_NAME}@${PACKAGE_VERSION}" > /dev/null 2>&1; then + echo "Package ${PACKAGE_NAME}@${PACKAGE_VERSION} already exists. Skipping publish." + else + echo "Package ${PACKAGE_NAME}@${PACKAGE_VERSION} does not exist. Will publish." + npm publish + fi + + cd .. + env: + NPM_TOKEN: ${{ secrets.npm_token }} + + - name: Publish to Git Packages + shell: sh + run: | + npm config set registry https://git.lhprovedor.com.br/api/packages/${{ inputs.git_username }}/npm/ + npm config set -- '//git.lhprovedor.com.br/api/packages/${{ inputs.git_username }}/npm/:_authToken' "${GIT_TOKEN}" + cd dist + + if npm view "${PACKAGE_NAME}@${PACKAGE_VERSION}" > /dev/null 2>&1; then + echo "Package ${PACKAGE_NAME}@${PACKAGE_VERSION} already exists. Skipping publish." + else + echo "Package ${PACKAGE_NAME}@${PACKAGE_VERSION} does not exist. Will publish." + npm publish + fi + + cd .. + env: + GIT_TOKEN: ${{ inputs.git_token }} diff --git a/.vscode/settings.json b/.vscode/settings.json index eb60b31..6772390 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,3 @@ { - "cSpell.words": ["dbupdater", "lhprovedor", "webfactory"] + "cSpell.words": ["dbupdater", "lhprovedor", "npmjs", "webfactory"] }