|
| 1 | +name: Publish Workflow |
| 2 | +permissions: |
| 3 | + contents: read |
| 4 | + |
| 5 | +on: |
| 6 | + push: |
| 7 | + tag: |
| 8 | + - v* |
| 9 | + workflow_dispatch: |
| 10 | + inputs: |
| 11 | + release_version: |
| 12 | + description: Provide the tag to publish the package |
| 13 | + required: false |
| 14 | + fixed_cves: |
| 15 | + description: Provide the list of CVEs fixed by this version |
| 16 | + required: false |
| 17 | + |
| 18 | +jobs: |
| 19 | + build_test: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.release_version != '' }} |
| 22 | + |
| 23 | + steps: |
| 24 | + |
| 25 | + - name: Check out code |
| 26 | + uses: actions/checkout@v4.1.7 |
| 27 | + with: |
| 28 | + ref: ${{ github.event.inputs.release_version }} |
| 29 | + submodules: true |
| 30 | + |
| 31 | + - name: Set up Node.js |
| 32 | + uses: actions/setup-node@v2 |
| 33 | + with: |
| 34 | + node-version: '20' |
| 35 | + |
| 36 | + - name: Install JFrog CLI |
| 37 | + run: curl -fL https://install-cli.jfrog.io | sh |
| 38 | + |
| 39 | + - name: Clear npm cache |
| 40 | + run: npm cache clean --force |
| 41 | + |
| 42 | + - name: Configure .npmrc for JFrog |
| 43 | + run: | |
| 44 | + echo "registry=https://${{ secrets.JFROG_HOST_NAME }}/artifactory/api/npm/${{ secrets.NPM_GOS_ALL_ARTIFACTORY }}/" > ~/.npmrc |
| 45 | + echo "//${{ secrets.JFROG_HOST_NAME }}/artifactory/api/npm/${{ secrets.NPM_GOS_ALL_ARTIFACTORY }}/:_authToken=${{ secrets.CUSTOMER_ZERO_TOKEN }}" >> ~/.npmrc |
| 46 | + echo "always-auth=true" >> ~/.npmrc |
| 47 | +
|
| 48 | +
|
| 49 | + - name: Install dependencies for Node |
| 50 | + run: npm install 2>&1 | tee npm-install.log |
| 51 | + |
| 52 | + - name: Upload npm install log to Artifactory |
| 53 | + run: | |
| 54 | + PROJECT_NAME=${GITHUB_REPOSITORY##*/} |
| 55 | + jf rt u "npm-install.log" "${{ secrets.NPM_STAGING_ARTIFACTORY }}/logs/build_test/${PROJECT_NAME}-${{ github.event.inputs.release_version }}/" --url https://${{ secrets.JFROG_HOST_NAME }}/artifactory/ --access-token=${{ secrets.JFROG_PASSWORD }} |
| 56 | + |
| 57 | + - name: Run tests if available |
| 58 | + run: | |
| 59 | + if [ "$(node -p "require('./package.json').scripts?.test")" != "undefined" ]; then |
| 60 | + echo "Running tests..." |
| 61 | + npm test 2>&1 | tee npm-test.log |
| 62 | + PROJECT_NAME=${GITHUB_REPOSITORY##*/} |
| 63 | + jf rt u "npm-test.log" "${{ secrets.NPM_STAGING_ARTIFACTORY }}/logs/build_test/${PROJECT_NAME}-${{ github.event.inputs.release_version }}/" --url https://${{ secrets.JFROG_HOST_NAME }}/artifactory/ --access-token=${{ secrets.JFROG_PASSWORD }} |
| 64 | + else |
| 65 | + echo "No test script found, skipping." |
| 66 | + fi |
| 67 | +
|
| 68 | + publish: |
| 69 | + needs: build_test |
| 70 | + runs-on: ubuntu-latest |
| 71 | + if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.release_version != '' }} |
| 72 | + |
| 73 | + steps: |
| 74 | + - name: Checkout repository |
| 75 | + uses: actions/checkout@v4.1.7 |
| 76 | + with: |
| 77 | + ref: ${{ github.event.inputs.release_version }} |
| 78 | + submodules: true |
| 79 | + |
| 80 | + - name: Set up Node.js |
| 81 | + uses: actions/setup-node@v3 |
| 82 | + with: |
| 83 | + node-version: '20' |
| 84 | + |
| 85 | + - name: Install JFrog CLI |
| 86 | + run: curl -fL https://install-cli.jfrog.io | sh |
| 87 | + |
| 88 | + - name: Install dependencies for Node |
| 89 | + run: npm install |
| 90 | + |
| 91 | + - name: Read version and package |
| 92 | + run: | |
| 93 | + PACKAGE_FILENAME=$(npm pack --pack-destination ./ | grep -E '^[a-z]' | head -n 1) |
| 94 | + echo "PACKAGE_FILENAME=$PACKAGE_FILENAME" >> $GITHUB_ENV |
| 95 | +
|
| 96 | + - name: Import GPG private key |
| 97 | + run: | |
| 98 | + echo "${{ secrets.GPG_PRIVATE_KEY }}" | gpg --batch --import --pinentry-mode loopback |
| 99 | +
|
| 100 | + - name: Sign the .tgz package file |
| 101 | + run: | |
| 102 | + gpg --yes --pinentry-mode loopback \ |
| 103 | + --armor --detach-sign --local-user "${{ secrets.GPG_KEY_ID }}" "$PACKAGE_FILENAME" |
| 104 | +
|
| 105 | + - name: Configure .npmrc for JFrog |
| 106 | + run: | |
| 107 | + echo "registry=https://${{ secrets.JFROG_HOST_NAME }}/artifactory/api/npm/${{ secrets.NPM_STAGING_ARTIFACTORY }}/" > ~/.npmrc |
| 108 | + echo "//${{ secrets.JFROG_HOST_NAME }}/artifactory/api/npm/${{ secrets.NPM_STAGING_ARTIFACTORY }}/:_authToken=${{ secrets.JFROG_PASSWORD }}" >> ~/.npmrc |
| 109 | + echo "always-auth=true" >> ~/.npmrc |
| 110 | +
|
| 111 | + - name: Publish package to JFrog |
| 112 | + run: npm publish "$PACKAGE_FILENAME" 2>&1 | tee npm-publish.log |
| 113 | + env: |
| 114 | + NODE_AUTH_TOKEN: ${{ secrets.JFROG_PASSWORD }} |
| 115 | + |
| 116 | + - name: Upload publish log to Artifactory |
| 117 | + run: | |
| 118 | + PROJECT_NAME=${GITHUB_REPOSITORY##*/} |
| 119 | + jf rt u "npm-publish.log" "${{ secrets.NPM_STAGING_ARTIFACTORY }}/logs/publish/${PROJECT_NAME}-${{ github.event.inputs.release_version }}/" --url https://${{ secrets.JFROG_HOST_NAME }}/artifactory/ --access-token=${{ secrets.JFROG_PASSWORD }} |
| 120 | +
|
| 121 | + - name: Upload signature file to Artifactory |
| 122 | + run: | |
| 123 | + PROJECT_NAME=${GITHUB_REPOSITORY##*/} |
| 124 | + jf rt u "${PACKAGE_FILENAME}.asc" "${{ secrets.NPM_STAGING_ARTIFACTORY }}/${PROJECT_NAME}/-/" --url https://${{ secrets.JFROG_HOST_NAME }}/artifactory/ --access-token=${{ secrets.JFROG_PASSWORD }} |
| 125 | +
|
| 126 | + - name: Set CVE property in Artifactory |
| 127 | + # Property is set on the signature file to prevent multiple calls |
| 128 | + run: | |
| 129 | + PROJECT_NAME=${GITHUB_REPOSITORY##*/} |
| 130 | + jf rt sp "${{ secrets.NPM_STAGING_ARTIFACTORY }}/${PROJECT_NAME}/-/${PACKAGE_FILENAME}.asc" "fixed_cves=${{ github.event.inputs.fixed_cves }}" --url https://${{ secrets.JFROG_HOST_NAME }}/artifactory/ --access-token ${{ secrets.JFROG_PASSWORD }} |
| 131 | +
|
0 commit comments