|
| 1 | +name: CI/CD |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + pull_request: |
| 8 | + types: [opened, synchronize, reopened] |
| 9 | + |
| 10 | +concurrency: ${{ github.workflow }}-${{ github.ref }} |
| 11 | + |
| 12 | +jobs: |
| 13 | + # Changeset check - only runs on PRs |
| 14 | + changeset-check: |
| 15 | + name: Check for Changesets |
| 16 | + runs-on: ubuntu-latest |
| 17 | + if: github.event_name == 'pull_request' |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@v4 |
| 20 | + with: |
| 21 | + fetch-depth: 0 |
| 22 | + |
| 23 | + - name: Setup Node.js |
| 24 | + uses: actions/setup-node@v4 |
| 25 | + with: |
| 26 | + node-version: '20.x' |
| 27 | + |
| 28 | + - name: Install dependencies |
| 29 | + working-directory: ./js |
| 30 | + run: npm install |
| 31 | + |
| 32 | + - name: Check for changesets |
| 33 | + run: | |
| 34 | + # Skip changeset check for automated version PRs |
| 35 | + if [[ "${{ github.head_ref }}" == "changeset-release/"* ]]; then |
| 36 | + echo "Skipping changeset check for automated release PR" |
| 37 | + exit 0 |
| 38 | + fi |
| 39 | +
|
| 40 | + # Run changeset validation script |
| 41 | + node scripts/validate-changeset.mjs |
| 42 | +
|
| 43 | + # Test JavaScript |
| 44 | + test-js: |
| 45 | + name: Test JavaScript |
| 46 | + runs-on: ubuntu-latest |
| 47 | + needs: [changeset-check] |
| 48 | + if: always() && (github.event_name == 'push' || needs.changeset-check.result == 'success') |
| 49 | + steps: |
| 50 | + - uses: actions/checkout@v4 |
| 51 | + |
| 52 | + - name: Setup Node.js |
| 53 | + uses: actions/setup-node@v4 |
| 54 | + with: |
| 55 | + node-version: '20.x' |
| 56 | + |
| 57 | + - name: Setup .NET |
| 58 | + uses: actions/setup-dotnet@v4 |
| 59 | + with: |
| 60 | + dotnet-version: '8.0.x' |
| 61 | + |
| 62 | + - name: Install clink |
| 63 | + run: dotnet tool install --global clink |
| 64 | + |
| 65 | + - name: Verify clink installation |
| 66 | + run: clink --version |
| 67 | + |
| 68 | + - name: Install dependencies |
| 69 | + working-directory: ./js |
| 70 | + run: npm install |
| 71 | + |
| 72 | + - name: Create test data directories |
| 73 | + run: | |
| 74 | + mkdir -p ./js/data |
| 75 | + mkdir -p ./data/auth-data/users |
| 76 | + mkdir -p ./data/menu-items |
| 77 | + mkdir -p ./js/backend/monolith/data/auth-data |
| 78 | + mkdir -p ./js/tests |
| 79 | +
|
| 80 | + - name: Run tests |
| 81 | + working-directory: ./js |
| 82 | + run: npm test |
| 83 | + |
| 84 | + # Test Python |
| 85 | + test-python: |
| 86 | + name: Test Python |
| 87 | + runs-on: ubuntu-latest |
| 88 | + needs: [changeset-check] |
| 89 | + if: always() && (github.event_name == 'push' || needs.changeset-check.result == 'success') |
| 90 | + steps: |
| 91 | + - uses: actions/checkout@v4 |
| 92 | + |
| 93 | + - name: Setup Python |
| 94 | + uses: actions/setup-python@v5 |
| 95 | + with: |
| 96 | + python-version: '3.11' |
| 97 | + |
| 98 | + - name: Setup .NET |
| 99 | + uses: actions/setup-dotnet@v4 |
| 100 | + with: |
| 101 | + dotnet-version: '8.0.x' |
| 102 | + |
| 103 | + - name: Install clink |
| 104 | + run: dotnet tool install --global clink |
| 105 | + |
| 106 | + - name: Verify clink installation |
| 107 | + run: clink --version |
| 108 | + |
| 109 | + - name: Install dependencies |
| 110 | + working-directory: ./python |
| 111 | + run: | |
| 112 | + python -m pip install --upgrade pip |
| 113 | + pip install -e ".[dev]" |
| 114 | +
|
| 115 | + - name: Create test data directories |
| 116 | + run: | |
| 117 | + mkdir -p ./python/data |
| 118 | + mkdir -p ./data/auth-data/users |
| 119 | + mkdir -p ./data/menu-items |
| 120 | +
|
| 121 | + - name: Run tests |
| 122 | + working-directory: ./python |
| 123 | + run: pytest |
| 124 | + |
| 125 | + # Release JavaScript - only runs on main after tests pass |
| 126 | + release-js: |
| 127 | + name: Release JavaScript |
| 128 | + runs-on: ubuntu-latest |
| 129 | + needs: [test-js, test-python] |
| 130 | + # Use always() to ensure this job runs even if changeset-check was skipped |
| 131 | + if: always() && github.ref == 'refs/heads/main' && github.event_name == 'push' && needs.test-js.result == 'success' && needs.test-python.result == 'success' |
| 132 | + permissions: |
| 133 | + contents: write |
| 134 | + pull-requests: write |
| 135 | + id-token: write |
| 136 | + steps: |
| 137 | + - uses: actions/checkout@v4 |
| 138 | + with: |
| 139 | + fetch-depth: 0 |
| 140 | + |
| 141 | + - name: Setup Node.js |
| 142 | + uses: actions/setup-node@v4 |
| 143 | + with: |
| 144 | + node-version: '20.x' |
| 145 | + registry-url: 'https://registry.npmjs.org' |
| 146 | + |
| 147 | + - name: Install dependencies |
| 148 | + working-directory: ./js |
| 149 | + run: npm install |
| 150 | + |
| 151 | + - name: Check for changesets |
| 152 | + id: check_changesets |
| 153 | + run: | |
| 154 | + # Count changeset files (excluding README.md and config.json) |
| 155 | + CHANGESET_COUNT=$(find .changeset -name "*.md" ! -name "README.md" | wc -l) |
| 156 | + echo "Found $CHANGESET_COUNT changeset file(s)" |
| 157 | + echo "has_changesets=$([[ $CHANGESET_COUNT -gt 0 ]] && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT |
| 158 | +
|
| 159 | + - name: Version packages and commit to main |
| 160 | + if: steps.check_changesets.outputs.has_changesets == 'true' |
| 161 | + id: version |
| 162 | + run: | |
| 163 | + # Configure git |
| 164 | + git config user.name "github-actions[bot]" |
| 165 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 166 | +
|
| 167 | + # Get current version before bump |
| 168 | + OLD_VERSION=$(node -p "require('./js/package.json').version") |
| 169 | + echo "Current version: $OLD_VERSION" |
| 170 | +
|
| 171 | + # Run changeset version to bump versions and update CHANGELOG |
| 172 | + cd js && npm run changeset:version && cd .. |
| 173 | +
|
| 174 | + # Get new version after bump |
| 175 | + NEW_VERSION=$(node -p "require('./js/package.json').version") |
| 176 | + echo "New version: $NEW_VERSION" |
| 177 | + echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT |
| 178 | +
|
| 179 | + # Check if there are changes to commit |
| 180 | + if [[ -n $(git status --porcelain) ]]; then |
| 181 | + echo "Changes detected, committing..." |
| 182 | +
|
| 183 | + # Stage all changes (package.json, package-lock.json, CHANGELOG.md, deleted changesets) |
| 184 | + git add -A |
| 185 | +
|
| 186 | + # Commit with version number as message |
| 187 | + git commit -m "$NEW_VERSION" \ |
| 188 | + -m "" \ |
| 189 | + -m "🤖 Generated with [Claude Code](https://claude.com/claude-code)" |
| 190 | +
|
| 191 | + # Push directly to main |
| 192 | + git push origin main |
| 193 | +
|
| 194 | + echo "✅ Version bump committed and pushed to main" |
| 195 | + echo "version_committed=true" >> $GITHUB_OUTPUT |
| 196 | + else |
| 197 | + echo "No changes to commit" |
| 198 | + echo "version_committed=false" >> $GITHUB_OUTPUT |
| 199 | + fi |
| 200 | +
|
| 201 | + - name: Publish to npm |
| 202 | + if: steps.version.outputs.version_committed == 'true' |
| 203 | + id: publish |
| 204 | + run: | |
| 205 | + # Pull the latest changes we just pushed |
| 206 | + git pull origin main |
| 207 | +
|
| 208 | + # Publish to npm |
| 209 | + cd js && npm run changeset:publish |
| 210 | +
|
| 211 | + echo "published=true" >> $GITHUB_OUTPUT |
| 212 | +
|
| 213 | + # Get published version |
| 214 | + PUBLISHED_VERSION=$(node -p "require('./js/package.json').version") |
| 215 | + echo "published_version=$PUBLISHED_VERSION" >> $GITHUB_OUTPUT |
| 216 | + echo "✅ Published @unidel2035/links-client@$PUBLISHED_VERSION to npm" |
| 217 | + env: |
| 218 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 219 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 220 | + |
| 221 | + - name: Create GitHub Release |
| 222 | + if: steps.publish.outputs.published == 'true' |
| 223 | + env: |
| 224 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 225 | + run: | |
| 226 | + VERSION="${{ steps.publish.outputs.published_version }}" |
| 227 | + TAG="v$VERSION" |
| 228 | +
|
| 229 | + echo "Creating GitHub release for $TAG..." |
| 230 | +
|
| 231 | + # Extract changelog entry for this version |
| 232 | + # Read from CHANGELOG.md between this version header and the next version header |
| 233 | + if [ -f js/CHANGELOG.md ]; then |
| 234 | + RELEASE_NOTES=$(awk "/## $VERSION/{flag=1; next} /## [0-9]/{flag=0} flag" js/CHANGELOG.md) |
| 235 | + fi |
| 236 | +
|
| 237 | + if [ -z "$RELEASE_NOTES" ]; then |
| 238 | + RELEASE_NOTES="Release $VERSION" |
| 239 | + fi |
| 240 | +
|
| 241 | + # Create release |
| 242 | + gh release create "$TAG" \ |
| 243 | + --title "$VERSION" \ |
| 244 | + --notes "$RELEASE_NOTES" \ |
| 245 | + --repo ${{ github.repository }} |
| 246 | +
|
| 247 | + echo "✅ Created GitHub release: $TAG" |
0 commit comments