diff --git a/.github/workflows/use-action.yaml b/.github/workflows/use-action.yaml index a7dc5e1..5fdd517 100644 --- a/.github/workflows/use-action.yaml +++ b/.github/workflows/use-action.yaml @@ -18,10 +18,15 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Read service account key + id: sa-key + run: echo "content=$(cat github-actions-metrics-key.json | jq -c)" >> $GITHUB_OUTPUT + - uses: ./ with: github-token: ${{ github.token }} - gcp-service-account-key: github-actions-metrics-key.json + gcp-project-id: jason-chainguard + gcp-service-account-key: ${{ steps.sa-key.outputs.content }} - uses: actions/setup-node@v4 with: diff --git a/.gitignore b/.gitignore index 6fad5b9..c354551 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,7 @@ coverage/ *.log tmp/ temp/ + +# Service account keys (do not commit) +*-key.json +*.key.json diff --git a/README.md b/README.md index d1e8618..6e3c0d4 100644 --- a/README.md +++ b/README.md @@ -228,13 +228,31 @@ npm install npm test ``` +### Build + +The action uses [@vercel/ncc](https://github.com/vercel/ncc) to compile the JavaScript and dependencies into a single file for distribution. + +```bash +npm run build +``` + +This creates: +- `dist/index.js` - Main entry point +- `dist/post/index.js` - Post-action with all dependencies + +**Important:** Always run `npm run build` before committing changes. The `dist/` directory must be committed for the action to work in GitHub Actions. + ### Project Structure ``` otel-action/ ├── action.yml # Action definition -├── index.js # Main entry point (no-op) -├── post.js # Post-action (collects & exports metrics) +├── index.js # Main entry point (source) +├── post.js # Post-action (source) +├── dist/ # Compiled action (committed) +│ ├── index.js # Built main entry +│ └── post/ +│ └── index.js # Built post-action ├── lib/ │ ├── config.js # Configuration parsing │ ├── collector.js # GitHub API metrics collection diff --git a/action.yml b/action.yml index 94cfbeb..d15b769 100644 --- a/action.yml +++ b/action.yml @@ -34,6 +34,6 @@ inputs: runs: using: 'node20' - main: 'index.js' - post: 'post.js' + main: 'dist/index.js' + post: 'dist/post/index.js' post-if: 'always()' diff --git a/package-lock.json b/package-lock.json index 7c7f3d3..6834f80 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,7 +17,9 @@ "@opentelemetry/sdk-metrics": "^1.28.0", "@opentelemetry/semantic-conventions": "^1.28.0" }, - "devDependencies": {} + "devDependencies": { + "@vercel/ncc": "^0.38.1" + } }, "node_modules/@actions/core": { "version": "1.11.1", @@ -335,6 +337,15 @@ "node": ">=14" } }, + "node_modules/@vercel/ncc": { + "version": "0.38.4", + "resolved": "https://registry.npmjs.org/@vercel/ncc/-/ncc-0.38.4.tgz", + "integrity": "sha512-8LwjnlP39s08C08J5NstzriPvW1SP8Zfpp1BvC2sI35kPeZnHfxVkCwu4/+Wodgnd60UtT1n8K8zw+Mp7J9JmQ==", + "dev": true, + "bin": { + "ncc": "dist/ncc/cli.js" + } + }, "node_modules/agent-base": { "version": "7.1.4", "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.4.tgz", diff --git a/package.json b/package.json index 61a55f8..62bdaea 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "description": "GitHub Action that collects workflow step metrics and exports them to OpenTelemetry/Google Cloud Monitoring", "main": "index.js", "scripts": { - "test": "node --test test/collector.test.js test/exporter.test.js" + "test": "node --test test/collector.test.js test/exporter.test.js", + "build": "ncc build index.js -o dist && ncc build post.js -o dist/post" }, "keywords": [ "github-actions", @@ -23,5 +24,7 @@ "@opentelemetry/sdk-metrics": "^1.28.0", "@opentelemetry/semantic-conventions": "^1.28.0" }, - "devDependencies": {} + "devDependencies": { + "@vercel/ncc": "^0.38.1" + } }