feat(ansible-example): add @ansible/example package, tests, CI, publish & deploy workflows, docs and changelog
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
name: CI — Node packages
|
||||
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- 'packages/**'
|
||||
pull_request:
|
||||
paths:
|
||||
- 'packages/**'
|
||||
|
||||
jobs:
|
||||
test-packages:
|
||||
name: Test packages/*
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '18'
|
||||
|
||||
- name: Run tests for each package
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
# Find all package directories under packages/ that contain a package.json
|
||||
packages=(packages/*)
|
||||
found=0
|
||||
|
||||
for p in "${packages[@]}"; do
|
||||
if [ -d "$p" ] && [ -f "$p/package.json" ]; then
|
||||
found=1
|
||||
echo "\n===== Package: $p ====="
|
||||
|
||||
echo "-> Installing dependencies in $p"
|
||||
(cd "$p" && npm ci) || (cd "$p" && npm install)
|
||||
|
||||
echo "-> Running tests in $p"
|
||||
(cd "$p" && npm test)
|
||||
|
||||
echo "-> Running pack-inspect in $p"
|
||||
(cd "$p" && npm run pack-inspect)
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$found" -eq 0 ]; then
|
||||
echo "No packages with package.json found under packages/"
|
||||
fi
|
||||
@@ -0,0 +1,77 @@
|
||||
name: Publish Ansible Example
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
workflow_dispatch: {}
|
||||
|
||||
jobs:
|
||||
verify:
|
||||
name: Verify package
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node.js 18
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '18'
|
||||
|
||||
- name: Install dependencies (packages/@ansible/example)
|
||||
working-directory: packages/@ansible/example
|
||||
run: |
|
||||
# prefer CI install when a lockfile exists, otherwise fall back to install
|
||||
if [ -f package-lock.json ] || [ -f pnpm-lock.yaml ] || [ -f yarn.lock ]; then
|
||||
npm ci
|
||||
else
|
||||
npm install
|
||||
fi
|
||||
|
||||
- name: Run tests
|
||||
working-directory: packages/@ansible/example
|
||||
run: npm test
|
||||
|
||||
- name: Run pack-inspect
|
||||
working-directory: packages/@ansible/example
|
||||
run: npm run pack-inspect
|
||||
|
||||
publish:
|
||||
name: Publish to npm
|
||||
runs-on: ubuntu-latest
|
||||
needs: verify
|
||||
if: ${{ ((github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) || (github.event_name == 'workflow_dispatch')) && (secrets.NPM_TOKEN != '') }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node.js 18
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '18'
|
||||
|
||||
- name: Create ephemeral .npmrc with token
|
||||
run: |
|
||||
set -euo pipefail
|
||||
# write token to a temporary npmrc with restricted permissions (0600)
|
||||
printf "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}\n" > ~/.npmrc
|
||||
chmod 600 ~/.npmrc
|
||||
|
||||
- name: Publish package
|
||||
working-directory: packages/@ansible/example
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
# publish publicly; rely on npmrc for auth
|
||||
npm publish --access public
|
||||
|
||||
- name: Remove ephemeral .npmrc (always)
|
||||
if: always()
|
||||
run: |
|
||||
set -euo pipefail
|
||||
# attempt secure removal, fall back to plain removal
|
||||
if [ -f ~/.npmrc ]; then
|
||||
shred -u -z ~/.npmrc 2>/dev/null || rm -f ~/.npmrc || true
|
||||
fi
|
||||
Reference in New Issue
Block a user