-
Notifications
You must be signed in to change notification settings - Fork 75
test airlock build #1206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
shreyakhajanchi
wants to merge
6
commits into
master
Choose a base branch
from
github-workflow
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
test airlock build #1206
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6b05f52
test airlock build
shreyakhajanchi 3180265
minor updates
shreyakhajanchi 77d08bc
removing the auth step
shreyakhajanchi ede8f10
add sa
shreyakhajanchi d945796
minor change
shreyakhajanchi 8b1e84c
modified script
shreyakhajanchi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| name: Build with Trusted Registry | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - master | ||
| pull_request: | ||
|
|
||
| jobs: | ||
| build: | ||
| # IMPORTANT: Your self-hosted runner MUST have the 'gcloud' CLI installed | ||
| # AND be authenticated to Google Cloud (e.g., via Application Default Credentials) | ||
| runs-on: self-hosted | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '18' | ||
|
|
||
| # --- 1. BACKUP package-lock.json --- | ||
| - name: Backup package-lock.json | ||
| id: backup_lockfile | ||
| working-directory: ${{ github.workspace }}/ui | ||
| run: | | ||
| if [ -f package-lock.json ]; then | ||
| # Create the backup file in the same directory | ||
| cp package-lock.json package-lock.json.bak | ||
| echo "Backed up package-lock.json to package-lock.json.bak" | ||
| else | ||
| echo "package-lock.json not found. Skipping backup." | ||
| fi | ||
|
|
||
| # --- 2. ARTIFACT REGISTRY AUTHENTICATION & .npmrc SETUP --- | ||
| - name: Configure .npmrc with Gcloud Token | ||
| id: configure_npmrc | ||
| working-directory: ${{ github.workspace }}/ui | ||
| run: | | ||
| #!/usr/bin/env bash | ||
| set -e | ||
|
|
||
| # Get the access token. This requires the runner to be authenticated. | ||
| REPO_TOKEN="$(gcloud auth print-access-token)" | ||
|
|
||
| # Create the .npmrc file in the 'ui' directory. | ||
| cat > .npmrc <<EOL | ||
| registry=https://us-npm.pkg.dev/artifact-foundry-prod/npm-3p-trusted/ | ||
| //us-npm.pkg.dev/artifact-foundry-prod/npm-3p-trusted/:always-auth=true | ||
| //us-npm.pkg.dev/artifact-foundry-prod/npm-3p-trusted/:_authToken=${REPO_TOKEN} | ||
| EOL | ||
|
|
||
| echo "Successfully created .npmrc in ui/" | ||
|
|
||
| # --- 3. INSTALL AND BUILD --- | ||
| - name: Install Dependencies and Build UI | ||
| id: build_ui | ||
| continue-on-error: true | ||
| working-directory: ${{ github.workspace }}/ui | ||
| run: | | ||
| set -e | ||
|
|
||
| # CRITICAL: Delete the existing package-lock.json so npm generates a new one | ||
| # using the authenticated registry, but does not use the old integrity hashes. | ||
| if [ -f package-lock.json ]; then | ||
| rm package-lock.json | ||
| fi | ||
|
|
||
| # Ensure a clean install | ||
| rm -rf node_modules | ||
|
|
||
| npm install | ||
| npm run build | ||
|
|
||
| # NOTE: If the install or build fails, the cleanup step runs next due to 'continue-on-error: true' | ||
|
|
||
| # --- 4. CLEANUP AND RESTORE --- | ||
| - name: Cleanup .npmrc, node_modules, and Restore package-lock.json | ||
| if: always() # Ensure this runs even if the install/build step failed | ||
| working-directory: ${{ github.workspace }}/ui | ||
| run: | | ||
| # 4a. Remove the generated .npmrc file | ||
| if [ -f .npmrc ]; then | ||
| rm .npmrc | ||
| echo "Removed temporary .npmrc" | ||
| fi | ||
|
|
||
| # 4b. Remove the dynamically generated package-lock.json (from the install) | ||
| if [ -f package-lock.json ]; then | ||
| rm package-lock.json | ||
| echo "Removed newly generated package-lock.json" | ||
| fi | ||
|
|
||
| # 4c. Restore the original package-lock.json | ||
| if [ -f package-lock.json.bak ]; then | ||
| mv package-lock.json.bak package-lock.json | ||
| echo "Restored original package-lock.json" | ||
| else | ||
| echo "No backup file found to restore." | ||
| fi | ||
|
|
||
| # 4d. Remove node_modules | ||
| if [ -d node_modules ]; then | ||
| rm -rf node_modules | ||
| echo "Removed node_modules directory" | ||
| fi | ||
|
|
||
| # --- 5. FAIL WORKFLOW (If Build Failed) --- | ||
| - name: Fail workflow if build failed | ||
| if: steps.build_ui.outcome != 'success' | ||
| run: | | ||
| echo "Build with trusted registry failed. Failing the workflow." | ||
| exit 1 | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / CodeQL
Workflow does not contain permissions Medium