Repository navigation
chore(ci): add initial package setup workflow COMPASS-11348 - #943
Merged
Merged
Conversation
Comment on lines
+31
to
+125
| name: Create package stub | ||
| runs-on: ubuntu-latest | ||
| env: | ||
| NPM_PACKAGE_NAME: ${{ inputs.packageName }} | ||
| NPM_ORG_NAME: ${{ inputs.orgName }} | ||
| NPM_TRUSTED_PUBLISHING_REPO_NAME: ${{ inputs.trustedPublishingRepoName }} | ||
| NPM_TRUSTED_PUBLISHING_PUBLISH_WORKFLOW_FILE: ${{ inputs.trustedPublishingPublishWorkflowFile }} | ||
| steps: | ||
| - name: Setup node v24 | ||
| uses: actions/setup-node@v7 | ||
| with: | ||
| node-version: 24 | ||
| cache: "npm" | ||
| - name: Install npm@12 | ||
| run: | | ||
| npm install -g npm@12 | ||
| - name: Create package stub | ||
| run: | | ||
| # Set up package.json | ||
| npm init --yes | ||
| npm pkg set name="$NPM_PACKAGE_NAME" | ||
| npm pkg set version="0.0.0-init.0" | ||
| npm pkg set publishConfig.access="public" | ||
| npm pkg set author="MongoDB Inc." | ||
| npm pkg delete license | ||
| if [[ -n "$NPM_TRUSTED_PUBLISHING_REPO_NAME" ]]; then | ||
| npm pkg set repository="github:$NPM_TRUSTED_PUBLISHING_REPO_NAME" | ||
| fi | ||
| # Even though it's a `fix` command, it also works like a package.json | ||
| # validator for unfixable errors. It also normalizes some of the | ||
| # package.json config we're setting | ||
| npm pkg fix | ||
|
|
||
| # Provide a bit of context for initial version | ||
| echo "# This is an empty placeholder package provisioned for further use\n" > README.md | ||
|
|
||
| # Print the package.json for debugging purposes | ||
| echo "Created package stub with the following package.json:" | ||
| echo "" | ||
| cat package.json | ||
|
|
||
| - name: Publish package | ||
| run: | | ||
| # Login first so that publish works | ||
|
|
||
| echo "Logging in before proceeding with publish..." | ||
| echo "" | ||
| echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" | ||
| echo "!!! THE FOLLOWING SCRIPT IS GOING TO PRINT A LOG IN URL !!!" | ||
| echo "!!! FOLLOW THE URL AND AUTHENTICATE TO PROCEED !!!" | ||
| echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" | ||
| echo "" | ||
|
|
||
| npm login --auth-type=web | ||
|
|
||
| # Publish will ask for authentication again even though we just logged | ||
| # in, no way around that | ||
|
|
||
| echo "" | ||
| echo "Logged in as $(npm whoami). Starting the publish..." | ||
| echo "" | ||
| echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" | ||
| echo "!!! THE FOLLOWING SCRIPT IS GOING TO PRINT A LOG IN URL !!!" | ||
| echo "!!! FOLLOW THE URL AND AUTHENTICATE TO PROCEED !!!" | ||
| echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" | ||
| echo "" | ||
|
|
||
| npm publish --auth-type=web --tag=latest | ||
|
|
||
| if [[ -n "$NPM_TRUSTED_PUBLISHING_REPO_NAME" ]]; then | ||
| echo "Configuring trusted publishing..." | ||
| echo "" | ||
| echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" | ||
| echo "!!! THE FOLLOWING SCRIPT IS GOING TO PRINT A LOG IN URL !!!" | ||
| echo "!!! FOLLOW THE URL AND AUTHENTICATE TO PROCEED !!!" | ||
| echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" | ||
| echo "" | ||
|
|
||
| npm trust github "$NPM_PACKAGE_NAME" \ | ||
| --repo="$NPM_TRUSTED_PUBLISHING_REPO_NAME" \ | ||
| --file="$NPM_TRUSTED_PUBLISHING_PUBLISH_WORKFLOW_FILE" \ | ||
| --allow-publish \ | ||
| --yes | ||
| fi | ||
|
|
||
| if [[ "$NPM_PACKAGE_NAME" != "@$NPM_ORG_NAME/"* ]]; then | ||
| echo "Adding package to the $NPM_ORG_NAME..." | ||
| echo "" | ||
| echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" | ||
| echo "!!! THE FOLLOWING SCRIPT IS GOING TO PRINT A LOG IN URL !!!" | ||
| echo "!!! FOLLOW THE URL AND AUTHENTICATE TO PROCEED !!!" | ||
| echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" | ||
| echo "" | ||
| npm access grant read-write "$NPM_ORG_NAME:developers" "$NPM_PACKAGE_NAME" | ||
| fi No newline at end of file |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
An attempt to automate most of the initial package setup, it's not possible to skip the manual login step, but this way we don't need to document in detail all the commands you need to run and make sure that even on initial publish no compromised code will end up in the repo.
The plan is to move this to its own repo, I'm just testing if this will even work as expected and as always with GHA there's no other way but to merge this (I'm going to revert when I'm done with testing)