diff --git a/.github/workflows/cd-analytics.yml b/.github/workflows/cd-analytics.yml index a6ef19f6..95c65746 100644 --- a/.github/workflows/cd-analytics.yml +++ b/.github/workflows/cd-analytics.yml @@ -98,7 +98,6 @@ jobs: - name: Publish working-directory: ${{ env.ARTIFACT_PATH }} run: | - npm publish --provenance --access public --workspace packages/shared npm publish --provenance --access public --workspace scripts/analytics env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/cd-shared.yml b/.github/workflows/cd-shared.yml new file mode 100644 index 00000000..9417639b --- /dev/null +++ b/.github/workflows/cd-shared.yml @@ -0,0 +1,103 @@ +name: Continuous Delivery Shared + +env: + ARTIFACT_NAME: build + ARTIFACT_PATH: ./ + +on: + workflow_call: + secrets: + NPM_TOKEN: + required: true + workflow_dispatch: + +concurrency: + group: cd-${{ github.ref }} + cancel-in-progress: false + +jobs: + dependencies: + name: Install Dependencies + runs-on: ubuntu-latest + steps: + - name: Code Checkout + uses: actions/checkout@v4 + + - name: Install NodeJS + uses: actions/setup-node@v4 + with: + node-version-file: .nvmrc + + - name: Cache Dependencies + id: cache + uses: actions/cache@v4 + with: + path: | + **/node_modules + key: cd-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + cd- + + - name: Install Dependencies + if: steps.cache.outputs.cache-hit != 'true' + run: npm install + + build: + name: Code Building + needs: dependencies + runs-on: ubuntu-latest + steps: + - name: Checkout Source Code + uses: actions/checkout@v4 + + - name: Install NodeJS + uses: actions/setup-node@v4 + with: + node-version-file: .nvmrc + + - name: Restore Dependencies + uses: actions/cache@v4 + with: + path: | + **/node_modules + key: cd-${{ hashFiles('**/package-lock.json') }} + + - name: Code Building + run: | + npm run build:shared + + - name: Upload Artifact + uses: actions/upload-artifact@v4 + with: + name: ${{ env.ARTIFACT_NAME }} + path: ${{ env.ARTIFACT_PATH }} + + npm-publish: + name: Publish to NPM + needs: build + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write + steps: + - name: Checkout Source Code + uses: actions/checkout@v4 + + - name: Install NodeJS + uses: actions/setup-node@v4 + with: + node-version-file: .nvmrc + registry-url: https://registry.npmjs.org + + - name: Download Artifact + uses: actions/download-artifact@v4 + with: + name: ${{ env.ARTIFACT_NAME }} + path: ${{ env.ARTIFACT_PATH }} + + - name: Publish + working-directory: ${{ env.ARTIFACT_PATH }} + run: | + npm publish --provenance --access public --workspace packages/shared + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index a7d5dad8..255dba5f 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -22,6 +22,7 @@ jobs: pull-requests: write outputs: release_created: ${{ steps.release.outputs.release_created }} + packages_shared_release_created: ${{ steps.release.outputs['packages/shared--release_created'] }} scripts_analytics_release_created: ${{ steps.release.outputs['scripts/analytics--release_created'] }} steps: - name: Code Checkout @@ -62,9 +63,17 @@ jobs: version_label: ${{ github.sha }} deployment_package: ./build.zip - deploy-analytics: - name: Deploy Analytics Script + publish-shared: + name: Publish Shared Package needs: release + if: ${{ needs.release.outputs.packages_shared_release_created }} + uses: ./.github/workflows/cd-shared.yml + secrets: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + + deploy-analytics: + name: Publish Analytics Script + needs: publish-shared if: ${{ needs.release.outputs.scripts_analytics_release_created }} uses: ./.github/workflows/cd-analytics.yml secrets: diff --git a/scripts/analytics/package.json b/scripts/analytics/package.json index f0783fe2..a7316899 100644 --- a/scripts/analytics/package.json +++ b/scripts/analytics/package.json @@ -10,9 +10,9 @@ "node": "20.x.x", "npm": "10.x.x" }, - "main": "./index.js", + "main": "./build/index.js", "bin": { - "@git-fit/analytics": "./index.js" + "@git-fit/analytics": "./build/index.js" }, "scripts": { "lint:type": "npx tsc --noEmit",