|
| 1 | +name: CI / Merge |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - staging |
| 7 | + - feature* |
| 8 | + |
| 9 | +jobs: |
| 10 | + check-lint: |
| 11 | + name: "Check / Lint" |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - uses: actions/checkout@v4 |
| 15 | + - name: Run linting |
| 16 | + run: | |
| 17 | + npm install |
| 18 | + npm run lint |
| 19 | + npm run lint-shell |
| 20 | +
|
| 21 | + check-build: |
| 22 | + name: "Check / Build" |
| 23 | + runs-on: ubuntu-latest |
| 24 | + steps: |
| 25 | + - uses: actions/checkout@v4 |
| 26 | + - name: Run build |
| 27 | + run: | |
| 28 | + npm install |
| 29 | + npm run build --verbose |
| 30 | +
|
| 31 | + check-matrix: |
| 32 | + name: "Check / Matrix" |
| 33 | + runs-on: ubuntu-latest |
| 34 | + outputs: |
| 35 | + matrix: ${{ steps.set-matrix.outputs.matrix }} |
| 36 | + steps: |
| 37 | + - uses: actions/checkout@v4 |
| 38 | + - id: set-matrix |
| 39 | + run: | |
| 40 | + files=$(find tests/* -maxdepth 0 -type d | sed 's/.*/"&"/' | paste -sd, -) |
| 41 | + files=$files,$(find tests/* -maxdepth 0 -type f | grep -e "/*.test.ts" | sed 's/.*/"&"/' | paste -sd, -) |
| 42 | + if [ -z "$files" ]; then |
| 43 | + echo "matrix={\"shard\":[]}" >> $GITHUB_OUTPUT |
| 44 | + else |
| 45 | + echo "matrix={\"shard\":[$files]}" >> $GITHUB_OUTPUT |
| 46 | + fi |
| 47 | +
|
| 48 | + check-test: |
| 49 | + name: "Check / Test" |
| 50 | + runs-on: ubuntu-latest |
| 51 | + strategy: |
| 52 | + fail-fast: false |
| 53 | + matrix: ${{fromJson(needs.check-matrix.outputs.matrix)}} |
| 54 | + needs: check-matrix |
| 55 | + steps: |
| 56 | + - uses: actions/checkout@v4 |
| 57 | + - name: Set artifact name |
| 58 | + run: echo "SLUG=$(echo ${{ matrix.shard }} | sed 's/[/.]/-/g')" >> $GITHUB_ENV |
| 59 | + - name: Run tests |
| 60 | + run: | |
| 61 | + npm install |
| 62 | + npm run test -- \ |
| 63 | + --coverageReporters json \ |
| 64 | + --coverage \ |
| 65 | + "${{ matrix.shard }}" |
| 66 | + mv tmp/coverage/coverage-final.json "tmp/coverage/${{ env.SLUG }}.json" |
| 67 | + - uses: actions/upload-artifact@v4 |
| 68 | + with: |
| 69 | + name: coverage-artifacts-${{ env.SLUG }} |
| 70 | + path: tmp/coverage/ |
| 71 | + |
| 72 | + check-coverage: |
| 73 | + name: "Check / Coverage" |
| 74 | + runs-on: ubuntu-latest |
| 75 | + needs: check-test |
| 76 | + steps: |
| 77 | + - uses: actions/checkout@v4 |
| 78 | + - uses: actions/download-artifact@v4 |
| 79 | + with: |
| 80 | + pattern: coverage-artifacts-* |
| 81 | + path: tmp/coverage/ |
| 82 | + merge-multiple: true |
| 83 | + - run: rm .npmrc |
| 84 | + - name: Merge coverage results |
| 85 | + run: npx nyc merge tmp/coverage/ tmp/coverage/cobertura-coverage.json |
| 86 | + - uses: actions/upload-artifact@v4 |
| 87 | + with: |
| 88 | + name: cobertura-coverage |
| 89 | + path: tmp/coverage/cobertura-coverage.json |
| 90 | + |
| 91 | + build-pull: |
| 92 | + name: "Build / Pull Request" |
| 93 | + runs-on: ubuntu-latest |
| 94 | + if: github.ref == 'refs/heads/staging' |
| 95 | + steps: |
| 96 | + - uses: actions/checkout@v4 |
| 97 | + - name: Create pull request |
| 98 | + env: |
| 99 | + GH_TOKEN: ${{ secrets.GH_TOKEN }} |
| 100 | + run: | |
| 101 | + gh pr create \ |
| 102 | + --head staging \ |
| 103 | + --base master \ |
| 104 | + --title "ci: merge staging to master" \ |
| 105 | + --body "This is an automatic PR generated by the CI/CD pipeline. This will be automatically fast-forward merged if successful." \ |
| 106 | + --assignee "@me" \ |
| 107 | + --no-maintainer-edit || true |
| 108 | + printf "Pipeline Attempt on $GITHUB_RUN_ID for $GITHUB_SHA\n\n$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" \ |
| 109 | + | gh pr comment staging \ |
| 110 | + --body-file - \ |
| 111 | + --repo "$GITHUB_REPOSITORY" |
| 112 | +
|
| 113 | + integration-merge: |
| 114 | + name: "Integration / Merge" |
| 115 | + runs-on: ubuntu-latest |
| 116 | + concurrency: |
| 117 | + group: integration-merge |
| 118 | + cancel-in-progress: true |
| 119 | + needs: |
| 120 | + - check-lint |
| 121 | + - check-build |
| 122 | + - check-test |
| 123 | + - build-pull |
| 124 | + if: github.ref == 'refs/heads/staging' |
| 125 | + steps: |
| 126 | + - uses: actions/checkout@v4 |
| 127 | + with: |
| 128 | + fetch-depth: 0 |
| 129 | + token: ${{ secrets.GH_TOKEN }} |
| 130 | + - name: Merge into master |
| 131 | + env: |
| 132 | + GH_TOKEN: ${{ secrets.GH_TOKEN }} |
| 133 | + GIT_AUTHOR_EMAIL: ${{ secrets.GIT_AUTHOR_EMAIL }} |
| 134 | + GIT_AUTHOR_NAME: ${{ secrets.GIT_AUTHOR_NAME }} |
| 135 | + GIT_COMMITTER_EMAIL: ${{ secrets.GIT_COMMITTER_EMAIL }} |
| 136 | + GIT_COMMITTER_NAME: ${{ secrets.GIT_COMMITTER_NAME }} |
| 137 | + run: | |
| 138 | + printf "Pipeline Succeeded on $GITHUB_RUN_ID for $GITHUB_SHA\n\n$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" \ |
| 139 | + | gh pr comment staging \ |
| 140 | + --body-file - \ |
| 141 | + --repo "$GITHUB_REPOSITORY" |
| 142 | + git checkout master |
| 143 | + git merge --ff-only "$GITHUB_SHA" |
| 144 | + git push origin master |
0 commit comments