|
| 1 | +name: 🚀 Main Branch Pipeline |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +jobs: |
| 9 | + # Step 1: Validate merge source |
| 10 | + validate-resource: |
| 11 | + name: Validate merge source |
| 12 | + runs-on: ubuntu-latest |
| 13 | + outputs: |
| 14 | + validated: ${{ steps.validate.outputs.result }} |
| 15 | + steps: |
| 16 | + - name: Check source branch |
| 17 | + id: validate |
| 18 | + run: | |
| 19 | + if [ "${{ github.head_ref }}" != "develop" ]; then |
| 20 | + echo "Error: Only develop branch can merge to main" |
| 21 | + echo "result=failure" >> $GITHUB_OUTPUT |
| 22 | + exit 1 |
| 23 | + else |
| 24 | + echo "Validation passed - source branch is develop" |
| 25 | + echo "result=success" >> $GITHUB_OUTPUT |
| 26 | + fi |
| 27 | +
|
| 28 | + # Step 2: Validate commit messages |
| 29 | + check-commits: |
| 30 | + name: Validate Commit Messages |
| 31 | + runs-on: ubuntu-latest |
| 32 | + needs: validate-resource |
| 33 | + if: needs.validate-resource.outputs.validated == 'success' |
| 34 | + outputs: |
| 35 | + commits-validated: ${{ steps.validate-commits.outputs.result }} |
| 36 | + steps: |
| 37 | + - name: ⬇️ Checkout code |
| 38 | + uses: actions/checkout@v3 |
| 39 | + with: |
| 40 | + fetch-depth: 0 |
| 41 | + |
| 42 | + - name: ⬢ Set up Node.js |
| 43 | + uses: actions/setup-node@v4 |
| 44 | + with: |
| 45 | + node-version: 20 |
| 46 | + |
| 47 | + - name: 📦 Install Commitlint |
| 48 | + run: | |
| 49 | + npm install --save-dev @commitlint/{config-conventional,cli} |
| 50 | +
|
| 51 | + - name: 🔍 Validate commit messages (entire branch) |
| 52 | + id: validate-commits |
| 53 | + run: | |
| 54 | + npx commitlint --from=$(git rev-list --max-parents=0 HEAD) --to=HEAD --verbose |
| 55 | + echo "result=success" >> $GITHUB_OUTPUT |
| 56 | +
|
| 57 | + # Step 3: Run Flutter tests |
| 58 | + test: |
| 59 | + name: Flutter Tests & Coverage |
| 60 | + runs-on: ubuntu-latest |
| 61 | + needs: check-commits |
| 62 | + if: needs.check-commits.outputs.commits-validated == 'success' |
| 63 | + outputs: |
| 64 | + tests-passed: ${{ steps.run-tests.outputs.result }} |
| 65 | + steps: |
| 66 | + - name: Checkout code |
| 67 | + uses: actions/checkout@v4 |
| 68 | + |
| 69 | + - name: Setup Flutter |
| 70 | + uses: subosito/flutter-action@v2 |
| 71 | + with: |
| 72 | + flutter-version: "3.29.3" |
| 73 | + architecture: "x64" |
| 74 | + |
| 75 | + - name: Install dependencies |
| 76 | + run: flutter pub get |
| 77 | + |
| 78 | + - name: Verify formatting |
| 79 | + run: dart format --set-exit-if-changed . |
| 80 | + |
| 81 | + - name: Analyze project source |
| 82 | + run: flutter analyze |
| 83 | + |
| 84 | + - name: Run tests with coverage |
| 85 | + id: run-tests |
| 86 | + run: | |
| 87 | + flutter test --coverage |
| 88 | + echo "result=success" >> $GITHUB_OUTPUT |
| 89 | +
|
| 90 | + # Step 4: Release |
| 91 | + release: |
| 92 | + name: Release |
| 93 | + runs-on: ubuntu-latest |
| 94 | + needs: test |
| 95 | + if: needs.test.outputs.tests-passed == 'success' |
| 96 | + steps: |
| 97 | + - name: ⬇️ Checkout code |
| 98 | + uses: actions/checkout@v3 |
| 99 | + with: |
| 100 | + fetch-depth: 0 |
| 101 | + |
| 102 | + - name: ⬢ Setup Node |
| 103 | + uses: actions/setup-node@v4 |
| 104 | + with: |
| 105 | + node-version: 20 |
| 106 | + |
| 107 | + - name: 📦 Install dependencies |
| 108 | + run: npm ci |
| 109 | + |
| 110 | + - name: 🚀 Run semantic-release |
| 111 | + env: |
| 112 | + GH_TOKEN: ${{ secrets.GH_TOKEN }} |
| 113 | + run: npx semantic-release |
0 commit comments