|
| 1 | +name: Deploy to Fly.io |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +jobs: |
| 9 | + deploy: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + |
| 12 | + steps: |
| 13 | + - name: Checkout main |
| 14 | + uses: actions/checkout@v4 |
| 15 | + with: |
| 16 | + ref: main |
| 17 | + fetch-depth: 0 |
| 18 | + |
| 19 | + - name: Set up Git |
| 20 | + run: | |
| 21 | + git config user.name "github-actions[bot]" |
| 22 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 23 | +
|
| 24 | + - name: Fetch deployment branch |
| 25 | + run: git fetch origin deployment:deployment |
| 26 | + |
| 27 | + - name: Attempt merge and resolve package conflicts |
| 28 | + id: merge_attempt |
| 29 | + run: | |
| 30 | + git checkout deployment |
| 31 | + # Attempt merge |
| 32 | + if ! git merge origin/main --no-edit; then |
| 33 | + # If merge fails due to package conflicts, reset and reinstall |
| 34 | + echo "MERGE_FAILED=true" >> $GITHUB_ENV |
| 35 | + exit 0 |
| 36 | + fi |
| 37 | + |
| 38 | + # After successful merge, ensure package consistency |
| 39 | + echo "Ensuring package consistency..." |
| 40 | + rm -rf node_modules/ package-lock.json |
| 41 | + npm install |
| 42 | + git add package-lock.json |
| 43 | + git commit -m "Update package-lock.json after merge" || echo "No package-lock changes" |
| 44 | + |
| 45 | + - name: Push to deployment branch |
| 46 | + if: env.MERGE_FAILED != 'true' |
| 47 | + run: | |
| 48 | + git push origin deployment |
| 49 | +
|
| 50 | + - name: Set up Node.js |
| 51 | + if: env.MERGE_FAILED != 'true' |
| 52 | + uses: actions/setup-node@v3 |
| 53 | + with: |
| 54 | + node-version: '22' |
| 55 | + cache: 'npm' |
| 56 | + |
| 57 | + - name: Install dependencies |
| 58 | + if: env.MERGE_FAILED != 'true' |
| 59 | + run: | |
| 60 | + npm ci # Uses package-lock.json for exact versions |
| 61 | +
|
| 62 | + - name: Deploy to Fly.io |
| 63 | + if: env.MERGE_FAILED != 'true' |
| 64 | + uses: superfly/flyctl-actions@1.4 |
| 65 | + with: |
| 66 | + args: deploy --remote-only |
| 67 | + env: |
| 68 | + FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} |
0 commit comments