Skip to content

Commit be3ba22

Browse files
cholgateSCbot-snapci
authored andcommitted
Internal Change
GitOrigin-RevId: ec05244dcf19204e962b20a07b2673587c919569
1 parent 8bf5773 commit be3ba22

File tree

15 files changed

+218
-30
lines changed

15 files changed

+218
-30
lines changed

.github/workflows/README.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# GitHub Workflows
2+
3+
## NPM Package Publishing
4+
5+
The `publish-npm.yml` workflow automatically publishes npm packages to the public npm registry when their `package.json` files are updated.
6+
7+
### Packages
8+
9+
This workflow handles publishing for:
10+
- **@snap/valdi** (`npm_modules/cli/`) - CLI tools for Valdi development (available as `valdi` command)
11+
- **@snap/eslint-plugin-valdi** (`npm_modules/eslint-plugin-valdi/`) - ESLint rules for Valdi
12+
13+
### Trigger Conditions
14+
15+
The workflow runs when:
16+
1. Changes are pushed to `main` or `master` branch
17+
2. The changes include modifications to `npm_modules/*/package.json`
18+
3. Manual trigger via workflow_dispatch
19+
20+
### How It Works
21+
22+
1. **Detect Changes**: Determines which package.json files were modified
23+
2. **Build & Publish**: For each changed package:
24+
- Checks out the code
25+
- Sets up Node.js 20
26+
- Installs dependencies with `npm ci`
27+
- Builds the package with `npm run build`
28+
- Publishes to npm registry with `npm publish --access public`
29+
30+
### Setup Requirements
31+
32+
#### NPM Token
33+
34+
You must configure an `NPM_TOKEN` secret in your GitHub repository:
35+
36+
1. **Create an NPM Access Token**:
37+
- Log in to [npmjs.com](https://www.npmjs.com/)
38+
- Go to Account Settings → Access Tokens
39+
- Click "Generate New Token" → "Classic Token"
40+
- Select "Automation" type
41+
- Copy the generated token
42+
43+
2. **Add Secret to GitHub**:
44+
- Go to your GitHub repository
45+
- Navigate to Settings → Secrets and variables → Actions
46+
- Click "New repository secret"
47+
- Name: `NPM_TOKEN`
48+
- Value: Paste your npm access token
49+
- Click "Add secret"
50+
51+
#### Package Publishing Permissions
52+
53+
Ensure the npm account associated with the token has:
54+
- Publishing rights for the `@snap` organization (for both `@snap/valdi` and `@snap/eslint-plugin-valdi`)
55+
56+
### Usage
57+
58+
To publish a new version of a package:
59+
60+
1. Update the version in the package's `package.json`:
61+
```bash
62+
cd npm_modules/cli # or eslint-plugin-valdi
63+
npm version patch # or minor, major
64+
```
65+
66+
2. Commit and push the changes:
67+
```bash
68+
git add package.json
69+
git commit -m "Bump @snap/valdi version to X.Y.Z"
70+
git push origin main
71+
```
72+
73+
3. The workflow will automatically:
74+
- Detect the package.json change
75+
- Build the package
76+
- Publish it to npm
77+
78+
### Manual Trigger
79+
80+
You can also manually trigger the workflow:
81+
1. Go to Actions tab in GitHub
82+
2. Select "Publish NPM Packages" workflow
83+
3. Click "Run workflow"
84+
4. Select the branch and click "Run workflow"
85+
86+
Note: Manual triggers will attempt to publish all packages, so ensure versions have been updated to avoid npm publish errors.
87+
88+
### Troubleshooting
89+
90+
- **401 Unauthorized**: Check that the `NPM_TOKEN` secret is correctly configured
91+
- **403 Forbidden**: Ensure the npm account has publishing permissions for the package
92+
- **Version already exists**: Update the version number in package.json before publishing
93+
- **Build failures**: Check that the package builds successfully locally before pushing
94+

.github/workflows/publish-npm.yml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: Publish NPM Packages
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
paths:
9+
- 'npm_modules/*/package.json'
10+
workflow_dispatch:
11+
12+
jobs:
13+
detect-changes:
14+
runs-on: ubuntu-latest
15+
outputs:
16+
cli: ${{ steps.filter.outputs.cli }}
17+
eslint-plugin: ${{ steps.filter.outputs.eslint-plugin }}
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 2
23+
24+
- name: Check which packages changed
25+
id: filter
26+
run: |
27+
if git diff HEAD^ HEAD --name-only | grep -q "npm_modules/cli/package.json"; then
28+
echo "cli=true" >> $GITHUB_OUTPUT
29+
else
30+
echo "cli=false" >> $GITHUB_OUTPUT
31+
fi
32+
33+
if git diff HEAD^ HEAD --name-only | grep -q "npm_modules/eslint-plugin-valdi/package.json"; then
34+
echo "eslint-plugin=true" >> $GITHUB_OUTPUT
35+
else
36+
echo "eslint-plugin=false" >> $GITHUB_OUTPUT
37+
fi
38+
39+
publish-cli:
40+
needs: detect-changes
41+
if: needs.detect-changes.outputs.cli == 'true'
42+
runs-on: ubuntu-latest
43+
defaults:
44+
run:
45+
working-directory: npm_modules/cli
46+
steps:
47+
- name: Checkout code
48+
uses: actions/checkout@v4
49+
50+
- name: Setup Node.js
51+
uses: actions/setup-node@v4
52+
with:
53+
node-version: '20'
54+
registry-url: 'https://registry.npmjs.org'
55+
56+
- name: Install dependencies
57+
run: npm ci
58+
59+
- name: Build package
60+
run: npm run build
61+
62+
- name: Publish @snap/valdi to npm
63+
run: npm publish --access public
64+
env:
65+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
66+
67+
publish-eslint-plugin:
68+
needs: detect-changes
69+
if: needs.detect-changes.outputs.eslint-plugin == 'true'
70+
runs-on: ubuntu-latest
71+
defaults:
72+
run:
73+
working-directory: npm_modules/eslint-plugin-valdi
74+
steps:
75+
- name: Checkout code
76+
uses: actions/checkout@v4
77+
78+
- name: Setup Node.js
79+
uses: actions/setup-node@v4
80+
with:
81+
node-version: '20'
82+
registry-url: 'https://registry.npmjs.org'
83+
84+
- name: Install dependencies
85+
run: npm ci
86+
87+
- name: Build package
88+
run: npm run build
89+
90+
- name: Publish @snap/eslint-plugin-valdi to npm
91+
run: npm publish --access public
92+
env:
93+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
94+

apps/helloworld/.eslintrc.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = {
66
tsconfigRootDir: __dirname,
77
project: ['./src/valdi/_configs/eslint.tsconfig.json'],
88
},
9-
plugins: ['@typescript-eslint', 'unused-imports', 'rxjs', 'prettier', '@snapchat/eslint-plugin-valdi'],
9+
plugins: ['@typescript-eslint', 'unused-imports', 'rxjs', 'prettier', '@snap/eslint-plugin-valdi'],
1010
extends: [
1111
'eslint:recommended',
1212
'plugin:@typescript-eslint/recommended',
@@ -15,13 +15,13 @@ module.exports = {
1515
'prettier',
1616
],
1717
rules: {
18-
'@snapchat/valdi/attributed-text-no-array-assignment': 'error',
19-
'@snapchat/valdi/jsx-no-lambda': 'error',
20-
'@snapchat/valdi/assign-timer-id': 'error',
21-
'@snapchat/valdi/only-const-enum': 'off',
22-
'@snapchat/valdi/no-implicit-index-import': 'error',
23-
'@snapchat/valdi/mutate-state-without-set-state': 'error',
24-
'@snapchat/valdi/no-import-from-test-outside-test-dir': 'error',
25-
'@snapchat/valdi/no-declare-test-without-describe': 'error',
18+
'@snap/valdi/attributed-text-no-array-assignment': 'error',
19+
'@snap/valdi/jsx-no-lambda': 'error',
20+
'@snap/valdi/assign-timer-id': 'error',
21+
'@snap/valdi/only-const-enum': 'off',
22+
'@snap/valdi/no-implicit-index-import': 'error',
23+
'@snap/valdi/mutate-state-without-set-state': 'error',
24+
'@snap/valdi/no-import-from-test-outside-test-dir': 'error',
25+
'@snap/valdi/no-declare-test-without-describe': 'error',
2626
},
2727
};

apps/helloworld/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Valdi Helloworld app",
55
"license": "ISC",
66
"devDependencies": {
7-
"@snapchat/eslint-plugin-valdi": "1.0.1",
7+
"@snap/eslint-plugin-valdi": "1.0.1",
88
"@types/eslint": "^9.6.1",
99
"@types/jasmine": "^5.1.7",
1010
"@typescript-eslint/eslint-plugin": "^6.21.0",

apps/valdi_gpt/.eslintrc.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = {
66
tsconfigRootDir: __dirname,
77
project: ['./src/valdi/_configs/eslint.tsconfig.json'],
88
},
9-
plugins: ['@typescript-eslint', 'unused-imports', 'rxjs', 'prettier', '@snapchat/eslint-plugin-valdi'],
9+
plugins: ['@typescript-eslint', 'unused-imports', 'rxjs', 'prettier', '@snap/eslint-plugin-valdi'],
1010
extends: [
1111
'eslint:recommended',
1212
'plugin:@typescript-eslint/recommended',
@@ -15,13 +15,13 @@ module.exports = {
1515
'prettier',
1616
],
1717
rules: {
18-
'@snapchat/valdi/attributed-text-no-array-assignment': 'error',
19-
'@snapchat/valdi/jsx-no-lambda': 'error',
20-
'@snapchat/valdi/assign-timer-id': 'error',
21-
'@snapchat/valdi/only-const-enum': 'off',
22-
'@snapchat/valdi/no-implicit-index-import': 'error',
23-
'@snapchat/valdi/mutate-state-without-set-state': 'error',
24-
'@snapchat/valdi/no-import-from-test-outside-test-dir': 'error',
25-
'@snapchat/valdi/no-declare-test-without-describe': 'error',
18+
'@snap/valdi/attributed-text-no-array-assignment': 'error',
19+
'@snap/valdi/jsx-no-lambda': 'error',
20+
'@snap/valdi/assign-timer-id': 'error',
21+
'@snap/valdi/only-const-enum': 'off',
22+
'@snap/valdi/no-implicit-index-import': 'error',
23+
'@snap/valdi/mutate-state-without-set-state': 'error',
24+
'@snap/valdi/no-import-from-test-outside-test-dir': 'error',
25+
'@snap/valdi/no-declare-test-without-describe': 'error',
2626
},
2727
};

apps/valdi_gpt/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Valdi Helloworld app",
55
"license": "ISC",
66
"devDependencies": {
7-
"@snapchat/eslint-plugin-valdi": "1.0.1",
7+
"@snap/eslint-plugin-valdi": "1.0.1",
88
"@types/eslint": "^9.6.1",
99
"@types/jasmine": "^5.1.7",
1010
"@typescript-eslint/eslint-plugin": "^6.21.0",

npm_modules/cli/.bootstrap/apps/ui_application/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Valdi Helloworld app",
55
"license": "ISC",
66
"devDependencies": {
7-
"@snapchat/eslint-plugin-valdi": "1.0.2",
7+
"@snap/eslint-plugin-valdi": "1.0.2",
88
"@types/eslint": "^9.6.1",
99
"@types/jasmine": "^5.1.7",
1010
"@typescript-eslint/eslint-plugin": "^6.21.0",

npm_modules/cli/.metadata/package.json.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Valdi Helloworld app",
55
"license": "ISC",
66
"devDependencies": {
7-
"@snapchat/eslint-plugin-valdi": "1.0.2",
7+
"@snap/eslint-plugin-valdi": "1.0.2",
88
"@types/eslint": "^9.6.1",
99
"@types/jasmine": "^5.1.7",
1010
"@typescript-eslint/eslint-plugin": "^6.21.0",

npm_modules/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "valdi",
2+
"name": "@snap/valdi",
33
"version": "1.0.1",
44
"description": "Valdi CLI tools for developers",
55
"license": "ISC",

npm_modules/eslint-plugin-valdi/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@snapchat/eslint-plugin-valdi",
2+
"name": "@snap/eslint-plugin-valdi",
33
"version": "1.0.2",
44
"description": "ESLint rules for the Valdi project",
55
"main": "dist/index.js",

0 commit comments

Comments
 (0)