|
| 1 | +# Display Name of the workflow |
| 2 | +name: Build - Production |
| 3 | + |
| 4 | +# Event listeners for when the job should start execution |
| 5 | +on: |
| 6 | + # Allows you to run this workflow manually from the Actions tab |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | + # Run the build checks on every change |
| 10 | + push: |
| 11 | + branches: [main] |
| 12 | + pull_request: |
| 13 | + branches: [main] |
| 14 | + |
| 15 | + # Allow this workflow to be called from another workflow |
| 16 | + workflow_call: |
| 17 | + inputs: |
| 18 | + correlationId: |
| 19 | + description: 'Correlates the origin job with the child instance since process start does not return an ID.' |
| 20 | + type: string |
| 21 | + required: false |
| 22 | + outputs: |
| 23 | + packageName: |
| 24 | + description: 'The name of the generated NPM package.' |
| 25 | + value: ${{ jobs.Build-Prod.outputs.packageName }} |
| 26 | + |
| 27 | +# Define each session of execution that should be executed |
| 28 | +jobs: |
| 29 | + # Execution session that calculates the metadata for the build and makes it available to downstream jobs through outputs |
| 30 | + Metadata: |
| 31 | + # Human friendly name of the job |
| 32 | + name: Calculate - Metadata |
| 33 | + |
| 34 | + # Grant the required permissions to run the job |
| 35 | + permissions: |
| 36 | + contents: read |
| 37 | + |
| 38 | + # Execute the workflow |
| 39 | + uses: ./.github/workflows/Metadata.yml |
| 40 | + |
| 41 | + # Execution session that builds the artifacts that are used for deployment |
| 42 | + Build-Prod: |
| 43 | + # Display name of the job |
| 44 | + name: Build - Development Utilities |
| 45 | + |
| 46 | + # Configures the filter for which operating system that should be used when selecting runners |
| 47 | + runs-on: ubuntu-latest |
| 48 | + |
| 49 | + # Ensure dependant jobs have completed before running this job |
| 50 | + needs: [Metadata] |
| 51 | + |
| 52 | + # Sets the scopes available to the github_token injected to the GH Actions runner |
| 53 | + permissions: |
| 54 | + attestations: write |
| 55 | + contents: read |
| 56 | + id-token: write |
| 57 | + packages: write |
| 58 | + |
| 59 | + # Content that can be reused across multiple workflows to avoid duplication of code and logic |
| 60 | + outputs: |
| 61 | + packageName: ${{ steps.generate-package.outputs.package-file }} |
| 62 | + |
| 63 | + # Set of steps to execute to build and capture the static HTML |
| 64 | + steps: |
| 65 | + # Used to uniquely identify the specific call to correlate the calling entity with the cross repo build |
| 66 | + - name: ${{ github.event.inputs.correlationId }} |
| 67 | + id: correlationId |
| 68 | + background: true |
| 69 | + run: echo run identifier ${{ inputs.correlationId }} |
| 70 | + |
| 71 | + # Grab the source code from the repo |
| 72 | + - name: Checkout Files from Repo |
| 73 | + background: true |
| 74 | + uses: actions/checkout@v7 |
| 75 | + |
| 76 | + # Enable Node.JS in the build environment |
| 77 | + - name: Install - Node.JS Runtime |
| 78 | + uses: actions/setup-node@v6 |
| 79 | + background: true |
| 80 | + with: |
| 81 | + node-version: 24 |
| 82 | + registry-url: https://npm.pkg.github.com |
| 83 | + scope: software-hardware-integration-lab |
| 84 | + |
| 85 | + # Set up the socket firewall binary |
| 86 | + - name: Install - Socket Firewall |
| 87 | + uses: SocketDev/action@ba6de6cc0565af1f42295590380973573297e31f |
| 88 | + background: true |
| 89 | + with: |
| 90 | + mode: firewall-free |
| 91 | + |
| 92 | + # Bring job back to sync execution by awaiting for all async jobs to finish before continuing |
| 93 | + - name: Steps - Convert Back To Synchronous Execution - Environment Setup |
| 94 | + wait-all: true |
| 95 | + |
| 96 | + # Update the NPM CLI to the latest available version |
| 97 | + - name: Update NPM CLI |
| 98 | + run: sfw npm install -g npm |
| 99 | + |
| 100 | + # Installs the dependencies for building the project |
| 101 | + - name: Install - Dependencies |
| 102 | + run: sfw npm ci |
| 103 | + |
| 104 | + # Cryptographically attest that packages haven't been tampered where supported |
| 105 | + - name: Attest Dependency Provenance |
| 106 | + run: npm audit signatures |
| 107 | + |
| 108 | + # Update the version of SHIELD being uploaded to have a different version number to avoid SDG version conflict |
| 109 | + - name: Tattoo Version - Experimental Channel |
| 110 | + if: ${{ needs.Metadata.outputs.channel != 'stable' }} |
| 111 | + run: npm version --no-commit-hooks --no-git-tag-version "${{ needs.Metadata.outputs.version }}-${{ needs.Metadata.outputs.channel }}.${{ needs.Metadata.outputs.shortSha }}" |
| 112 | + |
| 113 | + # Compile the project |
| 114 | + - name: Build the Project |
| 115 | + run: npm run-script build:Prod |
| 116 | + |
| 117 | + # Publish the artifact to NPM with attestation |
| 118 | + - name: Upload Package to NPM Registry |
| 119 | + env: |
| 120 | + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 121 | + run: npm publish --tag ${{ needs.Metadata.outputs.channel }} |
| 122 | + |
| 123 | + # Generate the NPM package for beta and stable publishing, if required |
| 124 | + - name: Generate NPM Package |
| 125 | + id: generate-package |
| 126 | + run: echo "package-file=$(npm pack --ignore-scripts)" >> "$GITHUB_OUTPUT" |
| 127 | + |
| 128 | + # Create an attestation for the generated NPM package to ensure integrity and authenticity |
| 129 | + - name: Attest NPM Package |
| 130 | + uses: actions/attest@v4 |
| 131 | + with: |
| 132 | + subject-path: ${{ steps.generate-package.outputs.package-file }} |
| 133 | + |
| 134 | + # Upload the compiled HTML as an artifact for future consumption |
| 135 | + - name: Upload a Build Artifact |
| 136 | + uses: actions/upload-artifact@v7 |
| 137 | + with: |
| 138 | + name: NPM-Package |
| 139 | + if-no-files-found: error |
| 140 | + path: ${{ steps.generate-package.outputs.package-file }} |
0 commit comments