Skip to content

chore(ci): add initial package setup workflow COMPASS-11348 - #943

Merged
gribnoysup merged 1 commit into
mainfrom
poc-initial-package-creation-from-ci
Oct 30, 2026
Merged

gribnoysup merged 1 commit into
mainfrom
poc-initial-package-creation-from-ci

Conversation

@gribnoysup

Copy link
Copy Markdown
Collaborator

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)

@gribnoysup
gribnoysup requested review from a team as code owners October 30, 2026 17:24
@gribnoysup
gribnoysup requested a review from mabaasit October 30, 2026 17:24
@gribnoysup gribnoysup changed the title chore(ci): add initial package setup workflow chore(ci): add initial package setup workflow COMPASS-11348 Oct 30, 2026
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
@gribnoysup
gribnoysup merged commit 0c9dc8e into main Oct 30, 2026
18 checks passed
@gribnoysup
gribnoysup deleted the poc-initial-package-creation-from-ci branch October 30, 2026 17:26
@gribnoysup
gribnoysup restored the poc-initial-package-creation-from-ci branch October 30, 2026 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants