|
| 1 | +name: Gateway Release PR |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | + inputs: |
| 5 | + type: |
| 6 | + type: choice |
| 7 | + description: Choose release type |
| 8 | + options: |
| 9 | + - patch |
| 10 | + - minor |
| 11 | + - major |
| 12 | + default: patch |
| 13 | + beta: |
| 14 | + type: boolean |
| 15 | + description: Prerelease |
| 16 | + default: false |
| 17 | + |
| 18 | +permissions: |
| 19 | + contents: write |
| 20 | + pull-requests: write |
| 21 | + issues: write |
| 22 | + |
| 23 | +jobs: |
| 24 | + releaseIt: |
| 25 | + runs-on: ubuntu-latest |
| 26 | + steps: |
| 27 | + - uses: actions/checkout@v4 |
| 28 | + with: |
| 29 | + fetch-depth: 0 |
| 30 | + # Use the app token for checkout as well |
| 31 | + token: ${{ secrets.APP_INSTALLATION_TOKEN }} |
| 32 | + - name: git config |
| 33 | + run: | |
| 34 | + git config user.name "${GITHUB_ACTOR}" |
| 35 | + git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" |
| 36 | + - name: Setup node |
| 37 | + uses: actions/setup-node@v4 |
| 38 | + with: |
| 39 | + node-version: 20 |
| 40 | + cache: npm |
| 41 | + |
| 42 | + # Install dependencies from root (same as backend pipeline) |
| 43 | + - name: Install dependencies |
| 44 | + run: | |
| 45 | + npm ci || { |
| 46 | + echo "npm ci failed, trying clean install..." |
| 47 | + npm install --no-optional |
| 48 | + } |
| 49 | + |
| 50 | + - name: Gateway Build Test |
| 51 | + working-directory: services/gateway |
| 52 | + run: npm run build |
| 53 | + |
| 54 | + - name: Gateway Unit Tests |
| 55 | + working-directory: services/gateway |
| 56 | + run: npm run test:unit || echo "Tests not implemented yet, skipping" |
| 57 | + |
| 58 | + - name: Gateway Lint |
| 59 | + working-directory: services/gateway |
| 60 | + run: npm run lint || echo "Linting not configured yet, skipping" |
| 61 | + |
| 62 | + - name: Check for console.log in gateway |
| 63 | + working-directory: services/gateway |
| 64 | + run: npm run check:no-console || echo "Console check not configured yet, skipping" |
| 65 | + |
| 66 | + - name: Prepare release |
| 67 | + working-directory: services/gateway |
| 68 | + env: |
| 69 | + GITHUB_TOKEN: ${{ secrets.APP_INSTALLATION_TOKEN }} |
| 70 | + TYPE_ARG: ${{ fromJSON('{"patch":"patch", "minor":"minor", "major":"major"}')[github.event.inputs.type] }} |
| 71 | + BETA_ARG: ${{ github.event.inputs.beta == 'true' && '--preRelease=beta' || '' }} |
| 72 | + run: npm run release -- $TYPE_ARG --ci --verbose --no-git.push --no-git.commit --no-git.tag --no-github --no-npm $BETA_ARG |
| 73 | + - name: Update version.ts file |
| 74 | + working-directory: services/gateway |
| 75 | + run: | |
| 76 | + node scripts/update-version.js || echo "Version update script not found, skipping" |
| 77 | + if [ -f src/config/version.ts ]; then |
| 78 | + git add src/config/version.ts |
| 79 | + fi |
| 80 | + - name: get-npm-version |
| 81 | + id: package-version |
| 82 | + uses: martinbeentjes/npm-get-version-action@main |
| 83 | + with: |
| 84 | + path: services/gateway |
| 85 | + - name: Extract release notes |
| 86 | + id: extract-release-notes |
| 87 | + run: | |
| 88 | + # Get the current version from the package.json in the current working directory |
| 89 | + VERSION=$(cat package.json | grep '"version"' | cut -d'"' -f4) |
| 90 | + echo "Extracting release notes for version $VERSION" |
| 91 | + |
| 92 | + # Extract the changelog section for this version |
| 93 | + if [ -f CHANGELOG.md ]; then |
| 94 | + # Look for the version header and extract content until the next version or end of file |
| 95 | + RELEASE_NOTES=$(awk -v version="$VERSION" ' |
| 96 | + BEGIN { found=0; content="" } |
| 97 | + /^##? [0-9]+\.[0-9]+\.[0-9]+/ { |
| 98 | + if (found) exit |
| 99 | + if ($0 ~ version) { found=1; next } |
| 100 | + } |
| 101 | + found && /^##? [0-9]+\.[0-9]+\.[0-9]+/ { exit } |
| 102 | + found { content = content $0 "\n" } |
| 103 | + END { print content } |
| 104 | + ' CHANGELOG.md) |
| 105 | + |
| 106 | + # Remove empty lines |
| 107 | + CLEAN_NOTES=$(echo "$RELEASE_NOTES" | sed '/^$/d') |
| 108 | + |
| 109 | + # Save to output |
| 110 | + echo "release_notes<<EOF" >> $GITHUB_OUTPUT |
| 111 | + echo "$CLEAN_NOTES" >> $GITHUB_OUTPUT |
| 112 | + echo "EOF" >> $GITHUB_OUTPUT |
| 113 | + |
| 114 | + echo "Release notes extracted:" |
| 115 | + echo "$CLEAN_NOTES" |
| 116 | + else |
| 117 | + echo "No CHANGELOG.md found" |
| 118 | + echo "release_notes=" >> $GITHUB_OUTPUT |
| 119 | + fi |
| 120 | + working-directory: services/gateway |
| 121 | + - name: Create pull request |
| 122 | + uses: peter-evans/create-pull-request@v7 |
| 123 | + id: cpr |
| 124 | + with: |
| 125 | + # This is the key change - use the app token |
| 126 | + token: ${{ secrets.APP_INSTALLATION_TOKEN }} |
| 127 | + branch: gateway-release |
| 128 | + delete-branch: true |
| 129 | + commit-message: 'chore(gateway): release v${{ steps.package-version.outputs.current-version}}' |
| 130 | + title: '[Gateway Release] v${{ steps.package-version.outputs.current-version}}' |
| 131 | + body: | |
| 132 | + ## Gateway Release v${{ steps.package-version.outputs.current-version}} |
| 133 | + |
| 134 | + This PR prepares a new gateway release. |
| 135 | + |
| 136 | + When merged, this will: |
| 137 | + 1. Create a release tag |
| 138 | + 2. Build and publish the npm package to @deploystack/gateway |
| 139 | + |
| 140 | + The npm package will be available at: |
| 141 | + - `@deploystack/gateway@latest` |
| 142 | + - `@deploystack/gateway@v${{ steps.package-version.outputs.current-version}}` |
| 143 | + |
| 144 | + ### Installation |
| 145 | + ```bash |
| 146 | + npm install -g @deploystack/gateway@${{ steps.package-version.outputs.current-version}} |
| 147 | + ``` |
| 148 | + |
| 149 | + ## Release notes: |
| 150 | + ${{ steps.extract-release-notes.outputs.release_notes }} |
| 151 | + labels: | |
| 152 | + gateway |
| 153 | + release |
| 154 | + automated pr |
| 155 | + draft: false |
| 156 | + - name: Show PR link |
| 157 | + if: ${{ steps.cpr.outputs.pull-request-url }} |
| 158 | + run: | |
| 159 | + echo "Gateway Release v${{ steps.package-version.outputs.current-version}}' pull request - ${{ steps.cpr.outputs.pull-request-url }}" |
0 commit comments