|
| 1 | +name: Publish release-build branch |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + |
| 7 | +concurrency: |
| 8 | + group: release-build |
| 9 | + cancel-in-progress: true |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: write |
| 13 | + |
| 14 | +jobs: |
| 15 | + publish: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Checkout |
| 20 | + uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + fetch-depth: 0 |
| 23 | + |
| 24 | + - name: Setup Node |
| 25 | + uses: actions/setup-node@v4 |
| 26 | + with: |
| 27 | + node-version: 22 |
| 28 | + cache: npm |
| 29 | + |
| 30 | + - name: Install dependencies |
| 31 | + run: npm ci |
| 32 | + |
| 33 | + - name: Build |
| 34 | + run: npm run build |
| 35 | + |
| 36 | + - name: Prepare artifacts |
| 37 | + id: prep |
| 38 | + shell: bash |
| 39 | + env: |
| 40 | + ART_DIR: ${{ runner.temp }}/release-build |
| 41 | + run: | |
| 42 | + set -euo pipefail |
| 43 | +
|
| 44 | + SHORT_SHA="$(git rev-parse --short HEAD)" |
| 45 | +
|
| 46 | + rm -rf "$ART_DIR" |
| 47 | + mkdir -p "$ART_DIR" |
| 48 | +
|
| 49 | + cp -R dist "$ART_DIR/" |
| 50 | +
|
| 51 | + node -e " |
| 52 | + const fs = require('fs'); |
| 53 | + const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')); |
| 54 | + delete pkg.scripts; |
| 55 | + delete pkg.devDependencies; |
| 56 | + fs.writeFileSync(process.env.ART_DIR + '/package.json', JSON.stringify(pkg, null, 2)); |
| 57 | + " |
| 58 | +
|
| 59 | + [ -f README.md ] && cp README.md "$ART_DIR/" || true |
| 60 | + [ -f LICENSE ] && cp LICENSE "$ART_DIR/" || true |
| 61 | + [ -f CHANGELOG.md ] && cp CHANGELOG.md "$ART_DIR/" || true |
| 62 | +
|
| 63 | + echo "short_sha=$SHORT_SHA" >> "$GITHUB_OUTPUT" |
| 64 | + echo "art_dir=$ART_DIR" >> "$GITHUB_OUTPUT" |
| 65 | +
|
| 66 | + - name: Publish to release-build branch |
| 67 | + env: |
| 68 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 69 | + ART_DIR: ${{ steps.prep.outputs.art_dir }} |
| 70 | + SHORT_SHA: ${{ steps.prep.outputs.short_sha }} |
| 71 | + shell: bash |
| 72 | + run: | |
| 73 | + set -euo pipefail |
| 74 | +
|
| 75 | + cd "$ART_DIR" |
| 76 | + git init |
| 77 | + git config user.name "github-actions[bot]" |
| 78 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 79 | + git add . |
| 80 | + git commit -m "chore: release build for ${SHORT_SHA}" |
| 81 | +
|
| 82 | + git branch -M release-build |
| 83 | + git remote add origin "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" |
| 84 | + git push --force origin release-build |
0 commit comments