diff --git a/.github/workflows/release-build.yml b/.github/workflows/release-build.yml new file mode 100644 index 0000000..b50653e --- /dev/null +++ b/.github/workflows/release-build.yml @@ -0,0 +1,84 @@ +name: Publish release-build branch + +on: + push: + branches: [main] + +concurrency: + group: release-build + cancel-in-progress: true + +permissions: + contents: write + +jobs: + publish: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: 22 + cache: npm + + - name: Install dependencies + run: npm ci + + - name: Build + run: npm run build + + - name: Prepare artifacts + id: prep + shell: bash + env: + ART_DIR: ${{ runner.temp }}/release-build + run: | + set -euo pipefail + + SHORT_SHA="$(git rev-parse --short HEAD)" + + rm -rf "$ART_DIR" + mkdir -p "$ART_DIR" + + cp -R dist "$ART_DIR/" + + node -e " + const fs = require('fs'); + const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')); + delete pkg.scripts; + delete pkg.devDependencies; + fs.writeFileSync(process.env.ART_DIR + '/package.json', JSON.stringify(pkg, null, 2)); + " + + [ -f README.md ] && cp README.md "$ART_DIR/" || true + [ -f LICENSE ] && cp LICENSE "$ART_DIR/" || true + [ -f CHANGELOG.md ] && cp CHANGELOG.md "$ART_DIR/" || true + + echo "short_sha=$SHORT_SHA" >> "$GITHUB_OUTPUT" + echo "art_dir=$ART_DIR" >> "$GITHUB_OUTPUT" + + - name: Publish to release-build branch + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + ART_DIR: ${{ steps.prep.outputs.art_dir }} + SHORT_SHA: ${{ steps.prep.outputs.short_sha }} + shell: bash + run: | + set -euo pipefail + + cd "$ART_DIR" + git init + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add . + git commit -m "chore: release build for ${SHORT_SHA}" + + git branch -M release-build + git remote add origin "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" + git push --force origin release-build diff --git a/package.json b/package.json index 5682a0a..93ed38d 100644 --- a/package.json +++ b/package.json @@ -29,14 +29,13 @@ "scripts": { "clean": "rm -rf dist", "build": "npm run clean && tsc -p tsconfig.build.json", - "test": "node --test --experimental-strip-types --experimental-test-coverage src/**/*.test.*", + "test": "node --test --experimental-strip-types --experimental-test-coverage src/*.test.*", "lint": "oxlint", "lint:fix": "oxlint --fix --fix-suggestions", "format:check": "prettier --check .", "format:write": "prettier --write .", "type-check": "tsc --noEmit", - "download-schemas": "node scripts/sbom-schema-downloader.js", - "prepare": "npm run build" + "download-schemas": "node scripts/sbom-schema-downloader.js" }, "dependencies": { "@cyclonedx/cyclonedx-library": "^8.5.0",