92 lines
2.9 KiB
YAML
92 lines
2.9 KiB
YAML
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
|
|
package_owner:
|
|
description: user name that will hold the packages
|
|
required: false
|
|
default: Altsoft
|
|
git_url:
|
|
description: Git/Gitea/Forgejo server
|
|
required: false
|
|
default: git.lhprovedor.com.br
|
|
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=${{ inputs.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 ..
|
|
|
|
- name: Publish to Git Packages
|
|
shell: sh
|
|
run: |
|
|
echo "Git url: ${{ inputs.git_url }}"
|
|
echo "Package Owner: ${{ inputs.package_owner }}"
|
|
npm config set registry https://${{ inputs.git_url }}/api/packages/${{ inputs.package_owner }}/npm/
|
|
npm config set -- '//${{ inputs.git_url }}/api/packages/${{ inputs.package_owner }}/npm/:_authToken' "${{ inputs.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 ..
|