|
| 1 | +# SPDX-License-Identifier: CC-BY-4.0 OR GPL-3.0-or-later |
| 2 | +# This file is part of Network Pro |
| 3 | +# |
| 4 | +# When a release is created or this workflow is manually triggered, it will: |
| 5 | +# (1) confirm the CodeQL analysis was successful, (2) test JavaScript using |
| 6 | +# Mocha and Chai frameworks, (3) check linting with ESLint and formatting with |
| 7 | +# Prettier without making changes, (4) build the project using node 22.x on |
| 8 | +# ubuntu-24.04, and (5) publish the package to the npmjs and GPR registries. |
| 9 | +# |
| 10 | +# The workflow to upload static content to GitHub Pages (upload.yml) will |
| 11 | +# kick off following successful completion of this workflow. |
| 12 | +# |
| 13 | +# If needed, the upload-force.yml file can be manually triggered to force an |
| 14 | +# upload of static content from ./dist to GitHub Pages. |
| 15 | +# |
| 16 | +# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages |
| 17 | + |
| 18 | +name: Build/Test, Publish to Registries |
| 19 | + |
| 20 | +on: |
| 21 | + release: |
| 22 | + types: [created] |
| 23 | + workflow_dispatch: |
| 24 | + |
| 25 | +jobs: |
| 26 | + check-codeql: |
| 27 | + name: Check CodeQL Analysis |
| 28 | + runs-on: ubuntu-24.04 |
| 29 | + # Continue workflow even if this job fails due to inability to find and/or check CodeQL workflow |
| 30 | + continue-on-error: true |
| 31 | + steps: |
| 32 | + - name: Checkout repository |
| 33 | + |
| 34 | + |
| 35 | + - name: Set up GitHub CLI |
| 36 | + run: sudo apt-get install gh |
| 37 | + |
| 38 | + - name: Authenticate GitHub CLI |
| 39 | + env: |
| 40 | + GH_PAT: ${{ secrets.GH_PAT }} |
| 41 | + run: echo "${{ secrets.GH_PAT }}" | gh auth login --with-token |
| 42 | + |
| 43 | + - name: Check CodeQL Workflow |
| 44 | + env: |
| 45 | + GH_PAT: ${{ secrets.GH_PAT }} |
| 46 | + run: | |
| 47 | + gh run list --workflow "CodeQL" --json conclusion --jq '.[0].conclusion' > codeql_status.txt |
| 48 | + CODEQL_STATUS=$(cat codeql_status.txt) |
| 49 | + if [[ "$CODEQL_STATUS" != "success" ]]; then |
| 50 | + echo "CodeQL Analysis did not succeed. Exiting..." |
| 51 | + exit 1 |
| 52 | + fi |
| 53 | + rm codeql_status.txt |
| 54 | +
|
| 55 | + build: |
| 56 | + needs: check-codeql |
| 57 | + runs-on: ubuntu-24.04 |
| 58 | + steps: |
| 59 | + - name: Checkout repository |
| 60 | + |
| 61 | + |
| 62 | + - name: Set up Node.js |
| 63 | + |
| 64 | + with: |
| 65 | + node-version: 22.x |
| 66 | + |
| 67 | + - name: Cache Node.js modules |
| 68 | + |
| 69 | + with: |
| 70 | + path: ~/.npm |
| 71 | + key: ${{ runner.os }}-node-22.x-build-${{ hashFiles('package-lock.json') }} |
| 72 | + restore-keys: | |
| 73 | + ${{ runner.os }}-node-22.x-build- |
| 74 | + ${{ runner.os }}-node-22.x- |
| 75 | + ${{ runner.os }}-node- |
| 76 | +
|
| 77 | + - name: Install dependencies |
| 78 | + run: npm ci |
| 79 | + |
| 80 | + - name: Run tests using Mocha and Chai frameworks |
| 81 | + run: npm run test |
| 82 | + continue-on-error: true |
| 83 | + |
| 84 | + - name: Check linting and formatting |
| 85 | + run: npm run lint |
| 86 | + continue-on-error: true |
| 87 | + |
| 88 | + - name: Build project |
| 89 | + run: npm run build |
| 90 | + |
| 91 | + - name: Ensure dist directory exists |
| 92 | + run: mkdir -p dist |
| 93 | + |
| 94 | + - name: Copy package.json to dist directory |
| 95 | + run: cp package.json dist/ |
| 96 | + |
| 97 | + publish-npm: |
| 98 | + needs: [check-codeql, build] |
| 99 | + runs-on: ubuntu-24.04 |
| 100 | + permissions: |
| 101 | + contents: read |
| 102 | + packages: write |
| 103 | + steps: |
| 104 | + - name: Set up .npmrc file for npmjs |
| 105 | + run: | |
| 106 | + echo "@neteng-pro:registry=https://registry.npmjs.org/" > ~/.npmrc |
| 107 | + echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" >> ~/.npmrc |
| 108 | +
|
| 109 | + - name: Login to npmjs registry |
| 110 | + run: npm login --registry=https://registry.npmjs.org/ --scope=@neteng-pro --always-auth --username "sundevil311" --authToken ${{secrets.NPM_TOKEN }} |
| 111 | + |
| 112 | + - name: Checkout repository |
| 113 | + |
| 114 | + |
| 115 | + - name: Set up Node.js |
| 116 | + |
| 117 | + with: |
| 118 | + node-version: 22.x |
| 119 | + registry-url: https://registry.npmjs.org/ |
| 120 | + |
| 121 | + - name: Cache Node.js modules |
| 122 | + |
| 123 | + with: |
| 124 | + path: ~/.npm |
| 125 | + key: ${{ runner.os }}-node-22.x-publish-${{ hashFiles('package-lock.json') }} |
| 126 | + restore-keys: | |
| 127 | + ${{ runner.os }}-node-22.x-publish- |
| 128 | + ${{ runner.os }}-node-22.x- |
| 129 | + ${{ runner.os }}-node- |
| 130 | +
|
| 131 | + - name: Install dependencies |
| 132 | + run: npm ci |
| 133 | + |
| 134 | + - name: Set up Git user |
| 135 | + run: | |
| 136 | + git config --global user.email "[email protected]" |
| 137 | + git config --global user.name "SunDevil311" |
| 138 | +
|
| 139 | + - name: Ensure dist directory exists |
| 140 | + run: mkdir -p dist |
| 141 | + |
| 142 | + - name: Copy package.json to dist directory |
| 143 | + run: cp package.json dist/ |
| 144 | + |
| 145 | + - name: Update package name for GPR |
| 146 | + run: | |
| 147 | + sed -i 's/"name": ".*"/"name": "@neteng-pro\/netwk-pro-web"/' dist/package.json |
| 148 | +
|
| 149 | + - name: Publish package |
| 150 | + working-directory: ./dist |
| 151 | + run: npm publish --access public |
| 152 | + env: |
| 153 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 154 | + |
| 155 | + publish-gpr: |
| 156 | + needs: [check-codeql, build] |
| 157 | + runs-on: ubuntu-24.04 |
| 158 | + # Complete workflow even if this job fails |
| 159 | + continue-on-error: true |
| 160 | + permissions: |
| 161 | + contents: read |
| 162 | + packages: write |
| 163 | + steps: |
| 164 | + - name: Checkout repository |
| 165 | + |
| 166 | + |
| 167 | + - name: Set up Node.js |
| 168 | + |
| 169 | + with: |
| 170 | + node-version: 22.x |
| 171 | + registry-url: https://npm.pkg.github.com/ |
| 172 | + |
| 173 | + - name: Cache Node.js modules |
| 174 | + |
| 175 | + with: |
| 176 | + path: ~/.npm |
| 177 | + key: ${{ runner.os }}-node-22.x-publish-${{ hashFiles('package-lock.json') }} |
| 178 | + restore-keys: | |
| 179 | + ${{ runner.os }}-node-22.x-publish- |
| 180 | + ${{ runner.os }}-node-22.x- |
| 181 | + ${{ runner.os }}-node- |
| 182 | +
|
| 183 | + - name: Install dependencies |
| 184 | + run: npm ci |
| 185 | + |
| 186 | + - name: Set up Git user |
| 187 | + run: | |
| 188 | + git config --global user.email "[email protected]" |
| 189 | + git config --global user.name "SunDevil311" |
| 190 | +
|
| 191 | + - name: Ensure dist directory exists |
| 192 | + run: mkdir -p dist |
| 193 | + |
| 194 | + - name: Copy package.json to dist directory |
| 195 | + run: cp package.json dist/ |
| 196 | + |
| 197 | + - name: Publish package |
| 198 | + working-directory: ./dist |
| 199 | + run: npm publish |
| 200 | + env: |
| 201 | + NODE_AUTH_TOKEN: ${{ secrets.GH_PAT }} |
0 commit comments