From 403aeac04918d1d470571b9da026782c28ce1681 Mon Sep 17 00:00:00 2001 From: Leandro Costa Date: Fri, 27 Jun 2025 11:27:56 -0300 Subject: [PATCH 1/8] feat: check-package-version --- .../actions/check-package-version/action.yaml | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .forgejo/actions/check-package-version/action.yaml diff --git a/.forgejo/actions/check-package-version/action.yaml b/.forgejo/actions/check-package-version/action.yaml new file mode 100644 index 0000000..d6e78f7 --- /dev/null +++ b/.forgejo/actions/check-package-version/action.yaml @@ -0,0 +1,37 @@ +name: Verify package.json version +description: This action will provide $PACKAGE_VERSION env variable, and + +inputs: + package_json_path: + description: Path to package.json file + default: package.json + +runs: + using: composite + steps: + - name: Instalando Dependencias + shell: sh + 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-package-version + shell: sh + run: | + OLD_VERSION=$(git show HEAD^:${{ inputs.package_json_path }} | jq -r '.version') + NEW_VERSION=$(jq -r '.version' ${{ inputs.package_json_path }}) + + echo "Versão anterior: $OLD_VERSION" + echo "Versão atual: $NEW_VERSION" + + echo "PACKAGE_VERSION=$NEW_VERSION" >> "$GITHUB_OUTPUT" + + if [ "$OLD_VERSION" != "$NEW_VERSION" ]; then + echo "version_changed=true" >> "$GITHUB_OUTPUT" + else + echo "version_changed=false" >> "$GITHUB_OUTPUT" + fi From 4ef0a2da9cb140c57be22f45bbf4d1f53c390619 Mon Sep 17 00:00:00 2001 From: Leandro Costa Date: Fri, 27 Jun 2025 11:34:04 -0300 Subject: [PATCH 2/8] feat: definindo output --- .forgejo/actions/check-package-version/action.yaml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.forgejo/actions/check-package-version/action.yaml b/.forgejo/actions/check-package-version/action.yaml index d6e78f7..85335ce 100644 --- a/.forgejo/actions/check-package-version/action.yaml +++ b/.forgejo/actions/check-package-version/action.yaml @@ -5,6 +5,13 @@ inputs: package_json_path: description: Path to package.json file default: package.json +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 @@ -28,10 +35,10 @@ runs: echo "Versão anterior: $OLD_VERSION" echo "Versão atual: $NEW_VERSION" - echo "PACKAGE_VERSION=$NEW_VERSION" >> "$GITHUB_OUTPUT" - if [ "$OLD_VERSION" != "$NEW_VERSION" ]; then echo "version_changed=true" >> "$GITHUB_OUTPUT" else echo "version_changed=false" >> "$GITHUB_OUTPUT" fi + + echo "package_version=$NEW_VERSION" >> "$GITHUB_OUTPUT" From 55a2649c5e655cca68eaf0be02b499e5a0900133 Mon Sep 17 00:00:00 2001 From: Leandro Costa Date: Fri, 27 Jun 2025 12:14:10 -0300 Subject: [PATCH 3/8] feat: publish package --- .../actions/check-package-version/action.yaml | 2 + .../actions/publish-npm-package/action.yaml | 92 +++++++++++++++++++ .vscode/settings.json | 2 +- 3 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 .forgejo/actions/publish-npm-package/action.yaml 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"] } From 647ff5d810fb46c9214cada3d51f7afb162b1a71 Mon Sep 17 00:00:00 2001 From: Leandro Costa Date: Fri, 27 Jun 2025 12:26:32 -0300 Subject: [PATCH 4/8] fix: setando input pro env --- .forgejo/actions/publish-npm-package/action.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.forgejo/actions/publish-npm-package/action.yaml b/.forgejo/actions/publish-npm-package/action.yaml index 29a47c0..df3133b 100644 --- a/.forgejo/actions/publish-npm-package/action.yaml +++ b/.forgejo/actions/publish-npm-package/action.yaml @@ -76,8 +76,8 @@ runs: - 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}" + npm config set registry https://git.lhprovedor.com.br/api/packages/$GIT_USERNAME/npm/ + npm config set -- '//git.lhprovedor.com.br/api/packages/$GIT_USERNAME/npm/:_authToken' "${GIT_TOKEN}" cd dist if npm view "${PACKAGE_NAME}@${PACKAGE_VERSION}" > /dev/null 2>&1; then @@ -90,3 +90,4 @@ runs: cd .. env: GIT_TOKEN: ${{ inputs.git_token }} + GIT_USERNAME: ${{ inputs.git_username }} From 31a8d5c5b515bac56967cb1c27b09fac02ddd48c Mon Sep 17 00:00:00 2001 From: Leandro Costa Date: Fri, 27 Jun 2025 13:01:42 -0300 Subject: [PATCH 5/8] ci: using inputs.git_username --- .forgejo/actions/publish-npm-package/action.yaml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/.forgejo/actions/publish-npm-package/action.yaml b/.forgejo/actions/publish-npm-package/action.yaml index df3133b..e5b0f17 100644 --- a/.forgejo/actions/publish-npm-package/action.yaml +++ b/.forgejo/actions/publish-npm-package/action.yaml @@ -60,7 +60,7 @@ runs: shell: sh run: | cd dist - echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc + 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." @@ -70,14 +70,13 @@ runs: 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/$GIT_USERNAME/npm/ - npm config set -- '//git.lhprovedor.com.br/api/packages/$GIT_USERNAME/npm/:_authToken' "${GIT_TOKEN}" + echo "Git Username: ${{ inputs.git_username }}" + 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' "${{ inputs.git_token }}" cd dist if npm view "${PACKAGE_NAME}@${PACKAGE_VERSION}" > /dev/null 2>&1; then @@ -88,6 +87,3 @@ runs: fi cd .. - env: - GIT_TOKEN: ${{ inputs.git_token }} - GIT_USERNAME: ${{ inputs.git_username }} From 0ff0250ca6ec0221834834e347e16a7d5be3884e Mon Sep 17 00:00:00 2001 From: Leandro Costa Date: Fri, 27 Jun 2025 13:05:30 -0300 Subject: [PATCH 6/8] ci: add defaults --- .forgejo/actions/publish-npm-package/action.yaml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/.forgejo/actions/publish-npm-package/action.yaml b/.forgejo/actions/publish-npm-package/action.yaml index e5b0f17..6dab1a1 100644 --- a/.forgejo/actions/publish-npm-package/action.yaml +++ b/.forgejo/actions/publish-npm-package/action.yaml @@ -10,10 +10,12 @@ inputs: required: true git_username: description: user name that will hold the packages - required: true + required: false + default: leandro git_url: - description: user name that will hold the packages - required: true + description: Git/Gitea/Forgejo server + required: false + default: git.lhprovedor.com.br artifact_folder_name: description: The Artifact to be downloaded default: dist @@ -74,9 +76,10 @@ runs: - name: Publish to Git Packages shell: sh run: | + echo "Git url: ${{ inputs.git_url }}" echo "Git Username: ${{ inputs.git_username }}" - 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' "${{ inputs.git_token }}" + npm config set registry https://${{ inputs.git_url }}/api/packages/${{ inputs.git_username }}/npm/ + npm config set -- '//${{ inputs.git_url }}/api/packages/${{ inputs.git_username }}/npm/:_authToken' "${{ inputs.git_token }}" cd dist if npm view "${PACKAGE_NAME}@${PACKAGE_VERSION}" > /dev/null 2>&1; then From 6640f4aaf2df93f121259eb21741656677088020 Mon Sep 17 00:00:00 2001 From: Leandro Costa Date: Fri, 27 Jun 2025 13:11:11 -0300 Subject: [PATCH 7/8] feat: set package owner --- .forgejo/actions/publish-npm-package/action.yaml | 10 +++++----- .vscode/settings.json | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.forgejo/actions/publish-npm-package/action.yaml b/.forgejo/actions/publish-npm-package/action.yaml index 6dab1a1..5d22fdd 100644 --- a/.forgejo/actions/publish-npm-package/action.yaml +++ b/.forgejo/actions/publish-npm-package/action.yaml @@ -8,10 +8,10 @@ inputs: git_token: description: Token to publish packages required: true - git_username: + package_owner: description: user name that will hold the packages required: false - default: leandro + default: Altsoft git_url: description: Git/Gitea/Forgejo server required: false @@ -77,9 +77,9 @@ runs: shell: sh run: | echo "Git url: ${{ inputs.git_url }}" - echo "Git Username: ${{ inputs.git_username }}" - npm config set registry https://${{ inputs.git_url }}/api/packages/${{ inputs.git_username }}/npm/ - npm config set -- '//${{ inputs.git_url }}/api/packages/${{ inputs.git_username }}/npm/:_authToken' "${{ inputs.git_token }}" + 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 diff --git a/.vscode/settings.json b/.vscode/settings.json index 6772390..c8e2e56 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,3 @@ { - "cSpell.words": ["dbupdater", "lhprovedor", "npmjs", "webfactory"] + "cSpell.words": ["Altsoft", "dbupdater", "lhprovedor", "npmjs", "webfactory"] } From ab4e6935af8c908cd0fae8d6f59f6aaa1eec49dd Mon Sep 17 00:00:00 2001 From: Leandro Costa Date: Fri, 27 Jun 2025 20:36:25 -0300 Subject: [PATCH 8/8] feat: build-node-app --- .forgejo/actions/build-node-app/action.yaml | 54 +++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 .forgejo/actions/build-node-app/action.yaml diff --git a/.forgejo/actions/build-node-app/action.yaml b/.forgejo/actions/build-node-app/action.yaml new file mode 100644 index 0000000..ea0d16e --- /dev/null +++ b/.forgejo/actions/build-node-app/action.yaml @@ -0,0 +1,54 @@ +name: Verify package.json version +description: This action build a nodejs app, and run the tests + +inputs: + test_action: + description: Name of the test script + default: test + required: false + + build_action: + description: Name of the build script + default: build + required: false + + build_path: + description: Path of the build output + default: dist + required: false + + artifact_name: + description: Name for the generated artifact + default: dist + required: false + +runs: + using: composite + steps: + - name: Install dependencies + shell: sh + run: apk add nodejs + + - name: Git Clone + uses: actions/checkout@v4 + + - name: Restore Node Modules Cache + uses: actions/cache@v3 + with: + path: ~/.npm + key: ${{ runner.os }}-nodejs-${{ hashFiles('package-lock.json') }} + restore-keys: | + ${{ runner.os }}-nodejs- + + - name: Build and Test + shell: sh + run: | + npm install + npm run ${{ inputs.test_action }} + npm run ${{ inputs.build_action }} + + - uses: actions/upload-artifact@v3 + name: Upload Artifact + with: + name: ${{ inputs.artifact_name }} + path: ${{ inputs.build_path }}