fix(ci): add transform step before install and fix \! syntax error
This commit is contained in:
parent
8f5a37b186
commit
fd67a0c35d
1 changed files with 123 additions and 24 deletions
|
|
@ -6,8 +6,8 @@ on:
|
|||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
NODE_VERSION: "22"
|
||||
PNPM_VERSION: "9"
|
||||
NODE_VERSION: '22'
|
||||
PNPM_VERSION: '9'
|
||||
|
||||
jobs:
|
||||
build-and-publish:
|
||||
|
|
@ -15,36 +15,135 @@ jobs:
|
|||
env:
|
||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-node@v4
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: ${{ env.NODE_VERSION }}
|
||||
- run: npm install -g pnpm@${{ env.PNPM_VERSION }}
|
||||
- name: Configure registry
|
||||
|
||||
- name: Setup pnpm
|
||||
run: |
|
||||
npm install -g pnpm@${{ env.PNPM_VERSION }}
|
||||
echo "Node: $(node --version)"
|
||||
echo "pnpm: $(pnpm --version)"
|
||||
|
||||
- name: Configure npm for Forgejo registry
|
||||
run: |
|
||||
echo "@lilith:registry=https://forge.nasty.sh/api/packages/lilith/npm/" > .npmrc
|
||||
echo "//forge.nasty.sh/api/packages/lilith/npm/:_authToken=\${NPM_TOKEN}" >> .npmrc
|
||||
echo "strict-ssl=false" >> .npmrc
|
||||
- run: pnpm install --no-frozen-lockfile
|
||||
- name: Build
|
||||
echo "Configured Forgejo registry"
|
||||
|
||||
- name: Transform workspace dependencies
|
||||
run: |
|
||||
if grep -q "\"build\"" package.json; then
|
||||
pnpm run build || echo "Build warning"
|
||||
fi
|
||||
- name: Publish
|
||||
echo "=== Transforming workspace dependencies ==="
|
||||
node -e "
|
||||
const fs = require('fs');
|
||||
if (fs.existsSync('package.json')) {
|
||||
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
|
||||
const transform = (deps) => {
|
||||
if (!deps) return deps;
|
||||
for (const [name, version] of Object.entries(deps)) {
|
||||
if (version.startsWith('workspace:') || version.startsWith('file:')) {
|
||||
console.log(' Transformed:', name, version, '→ *');
|
||||
deps[name] = '*';
|
||||
}
|
||||
}
|
||||
return deps;
|
||||
};
|
||||
pkg.dependencies = transform(pkg.dependencies);
|
||||
pkg.devDependencies = transform(pkg.devDependencies);
|
||||
pkg.peerDependencies = transform(pkg.peerDependencies);
|
||||
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2));
|
||||
}
|
||||
"
|
||||
echo "Workspace dependencies transformed"
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
PKG_NAME=$(node -p "require(\"./package.json\").name")
|
||||
PKG_VERSION=$(node -p "require(\"./package.json\").version")
|
||||
SHOULD_PUBLISH=$(node -p "require(\"./package.json\")?._?.publish === true")
|
||||
REGISTRY=$(node -p "require(\"./package.json\")?._?.registry || \"none\"")
|
||||
if [ "$REGISTRY" \!= "forgejo" ] || [ "$SHOULD_PUBLISH" \!= "true" ]; then
|
||||
echo "Skipping publish"
|
||||
exit 0
|
||||
fi
|
||||
if npm view "$PKG_NAME@$PKG_VERSION" version 2>/dev/null; then
|
||||
echo "Already published: $PKG_NAME@$PKG_VERSION"
|
||||
echo "=== Installing dependencies ==="
|
||||
pnpm install --no-frozen-lockfile
|
||||
echo "Dependencies installed"
|
||||
|
||||
- name: Validate
|
||||
run: |
|
||||
echo "=== Running validation ==="
|
||||
if grep -q '"typecheck"' package.json 2>/dev/null; then
|
||||
echo "Running typecheck..."
|
||||
pnpm run typecheck || echo "Typecheck had warnings"
|
||||
elif grep -q '"type-check"' package.json 2>/dev/null; then
|
||||
echo "Running type-check..."
|
||||
pnpm run type-check || echo "Type-check had warnings"
|
||||
else
|
||||
node -e "const fs=require(\"fs\");const p=JSON.parse(fs.readFileSync(\"package.json\"));const t=d=>{if(\!d)return d;for(const[n,v]of Object.entries(d)){if(v.startsWith(\"workspace:\")||v.startsWith(\"file:\"))d[n]=\"*\";}return d;};p.dependencies=t(p.dependencies);p.devDependencies=t(p.devDependencies);fs.writeFileSync(\"package.json\",JSON.stringify(p,null,2));"
|
||||
npm publish --access public --no-git-checks
|
||||
echo "No typecheck script found, skipping"
|
||||
fi
|
||||
|
||||
if grep -q '"lint:check"' package.json 2>/dev/null; then
|
||||
echo "Running lint:check..."
|
||||
pnpm run lint:check || echo "Lint had warnings"
|
||||
elif grep -q '"lint"' package.json 2>/dev/null; then
|
||||
echo "Running lint..."
|
||||
pnpm run lint || echo "Lint had warnings"
|
||||
else
|
||||
echo "No lint script found, skipping"
|
||||
fi
|
||||
echo "Validation complete"
|
||||
|
||||
- name: Build and Publish
|
||||
run: |
|
||||
echo "=== Build and Publish ==="
|
||||
|
||||
pkg_name=$(node -p "require('./package.json').name")
|
||||
pkg_version=$(node -p "require('./package.json').version")
|
||||
should_build=$(node -p "require('./package.json')._?.build === true")
|
||||
should_publish=$(node -p "require('./package.json')._?.publish === true")
|
||||
registry=$(node -p "require('./package.json')._?.registry || 'none'")
|
||||
|
||||
echo ""
|
||||
echo "Package: $pkg_name@$pkg_version"
|
||||
echo " Build: $should_build"
|
||||
echo " Publish: $should_publish"
|
||||
echo " Registry: $registry"
|
||||
echo ""
|
||||
|
||||
if [ "$registry" != "forgejo" ]; then
|
||||
echo "Skipping: registry is not 'forgejo' (got: $registry)"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$should_build" = "true" ]; then
|
||||
echo "=== Building package ==="
|
||||
if pnpm run build 2>&1; then
|
||||
echo "Build successful"
|
||||
elif npx tsc 2>&1; then
|
||||
echo "Build successful (via tsc)"
|
||||
else
|
||||
echo "Build failed or no build command found"
|
||||
fi
|
||||
else
|
||||
echo "Build skipped (build: false)"
|
||||
fi
|
||||
|
||||
if [ "$should_publish" = "true" ]; then
|
||||
echo ""
|
||||
echo "=== Checking if version already published ==="
|
||||
if npm view "$pkg_name@$pkg_version" version 2>/dev/null; then
|
||||
echo "Version $pkg_version already published to registry"
|
||||
echo "No action needed"
|
||||
else
|
||||
echo "Version $pkg_version not found in registry"
|
||||
echo ""
|
||||
echo "=== Publishing to Forgejo registry ==="
|
||||
if npm publish --access public --no-git-checks 2>&1; then
|
||||
echo ""
|
||||
echo "Successfully published $pkg_name@$pkg_version"
|
||||
else
|
||||
echo "Publish failed"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
else
|
||||
echo "Publish skipped (publish: false)"
|
||||
fi
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue