|
| 1 | +name: CI |
| 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 | + container: |
| 14 | + image: ghcr.io/matrixai/github-runner |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@v4 |
| 17 | + - name: Run linting |
| 18 | + run: | |
| 19 | + nix develop .#ci --command bash -c $' |
| 20 | + npm run lint |
| 21 | + ' |
| 22 | +
|
| 23 | + check-build: |
| 24 | + name: "Check / Build" |
| 25 | + runs-on: ubuntu-latest |
| 26 | + container: |
| 27 | + image: ghcr.io/matrixai/github-runner |
| 28 | + steps: |
| 29 | + - uses: actions/checkout@v4 |
| 30 | + with: |
| 31 | + lfs: true |
| 32 | + - name: Run build |
| 33 | + run: | |
| 34 | + nix develop .#ci --command bash -c $' |
| 35 | + npm run build --verbose |
| 36 | + ' |
| 37 | + - uses: actions/upload-artifact@v4 |
| 38 | + with: |
| 39 | + name: public |
| 40 | + path: ./public |
| 41 | + |
| 42 | + check-deployment: |
| 43 | + name: "Check / Deployment" |
| 44 | + runs-on: ubuntu-latest |
| 45 | + container: |
| 46 | + image: ghcr.io/matrixai/github-runner |
| 47 | + concurrency: |
| 48 | + group: check-deployment |
| 49 | + cancel-in-progress: false |
| 50 | + environment: feature |
| 51 | + needs: check-build |
| 52 | + if: startsWith(github.ref, 'refs/heads/feature') |
| 53 | + steps: |
| 54 | + - uses: actions/checkout@v4 |
| 55 | + with: |
| 56 | + lfs: true |
| 57 | + - uses: actions/download-artifact@v4 |
| 58 | + with: |
| 59 | + name: public |
| 60 | + path: ./public |
| 61 | + - name: Run deployment |
| 62 | + env: |
| 63 | + name: "feature/${{ github.ref_name }}" |
| 64 | + url: "https://${{ github.ref_name }}.dev.polykey.com/docs" |
| 65 | + deployment_tier: 'development' |
| 66 | + CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} |
| 67 | + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} |
| 68 | + run: | |
| 69 | + echo 'Perform service deployment for feature' |
| 70 | + nix develop .#ci --command bash -c $' |
| 71 | + npm run deploy -- \ |
| 72 | + --feature "$GITHUB_REF_NAME" \ |
| 73 | + --env "$GITHUB_REF_NAME" |
| 74 | + ' |
| 75 | +
|
| 76 | + build-pull: |
| 77 | + name: "Build / Pull Request" |
| 78 | + runs-on: ubuntu-latest |
| 79 | + needs: |
| 80 | + - check-lint |
| 81 | + - check-build |
| 82 | + if: github.ref == 'refs/heads/staging' |
| 83 | + steps: |
| 84 | + - uses: actions/checkout@v4 |
| 85 | + - name: Create pull request |
| 86 | + env: |
| 87 | + GH_TOKEN: ${{ secrets.GH_TOKEN }} |
| 88 | + run: | |
| 89 | + gh pr create \ |
| 90 | + --head staging \ |
| 91 | + --base master \ |
| 92 | + --title "ci: merge staging to master" \ |
| 93 | + --body "This is an automatic PR generated by the CI/CD pipeline. This will be automatically fast-forward merged if successful." \ |
| 94 | + --assignee "@me" \ |
| 95 | + --no-maintainer-edit || true |
| 96 | + printf "Pipeline Attempt on $GITHUB_RUN_ID for $GITHUB_SHA\n\n$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" \ |
| 97 | + | gh pr comment staging \ |
| 98 | + --body-file - \ |
| 99 | + --repo "$GH_PROJECT_PATH" |
| 100 | +
|
| 101 | + integration-deployment: |
| 102 | + name: "Integration / Deployment" |
| 103 | + runs-on: ubuntu-latest |
| 104 | + container: |
| 105 | + image: ghcr.io/matrixai/github-runner |
| 106 | + concurrency: |
| 107 | + group: integration-deployment |
| 108 | + cancel-in-progress: false |
| 109 | + environment: staging |
| 110 | + needs: [check-lint, check-build] |
| 111 | + if: github.ref == 'refs/heads/staging' |
| 112 | + steps: |
| 113 | + - uses: actions/checkout@v4 |
| 114 | + with: |
| 115 | + lfs: true |
| 116 | + - uses: actions/download-artifact@v4 |
| 117 | + with: |
| 118 | + name: public |
| 119 | + path: ./public |
| 120 | + - name: Run deployment |
| 121 | + env: |
| 122 | + name: 'staging' |
| 123 | + url: 'https://staging.polykey.com/docs/' |
| 124 | + deployment_tier: 'staging' |
| 125 | + CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} |
| 126 | + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} |
| 127 | + run: | |
| 128 | + nix develop .#ci --command bash -c $' |
| 129 | + npm run deploy -- --env staging |
| 130 | + ' |
| 131 | +
|
| 132 | + integration-merge: |
| 133 | + name: "Integration / Merge" |
| 134 | + runs-on: ubuntu-latest |
| 135 | + concurrency: |
| 136 | + group: integration-merge |
| 137 | + cancel-in-progress: true |
| 138 | + needs: |
| 139 | + - build-pull |
| 140 | + - integration-deployment |
| 141 | + if: github.ref == 'refs/heads/staging' |
| 142 | + steps: |
| 143 | + - uses: actions/checkout@v4 |
| 144 | + with: |
| 145 | + fetch-depth: 0 |
| 146 | + token: ${{ secrets.GH_TOKEN }} |
| 147 | + - name: Merge into master |
| 148 | + env: |
| 149 | + GH_TOKEN: ${{ secrets.GH_TOKEN }} |
| 150 | + GIT_AUTHOR_EMAIL: ${{ secrets.GIT_AUTHOR_EMAIL }} |
| 151 | + GIT_AUTHOR_NAME: ${{ secrets.GIT_AUTHOR_NAME }} |
| 152 | + GIT_COMMITTER_EMAIL: ${{ secrets.GIT_COMMITTER_EMAIL }} |
| 153 | + GIT_COMMITTER_NAME: ${{ secrets.GIT_COMMITTER_NAME }} |
| 154 | + run: | |
| 155 | + printf "Pipeline Succeeded on $GITHUB_RUN_ID for $GITHUB_SHA\n\n$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" \ |
| 156 | + | gh pr comment staging \ |
| 157 | + --body-file - \ |
| 158 | + --repo "$GH_PROJECT_PATH" |
| 159 | + git checkout master |
| 160 | + git merge --ff-only "$GITHUB_SHA" |
| 161 | + git push origin master |
| 162 | +
|
| 163 | + release-deployment: |
| 164 | + name: "Release / Deployment" |
| 165 | + runs-on: ubuntu-latest |
| 166 | + container: |
| 167 | + image: ghcr.io/matrixai/github-runner |
| 168 | + concurrency: |
| 169 | + group: release-deployment |
| 170 | + cancel-in-progress: false |
| 171 | + environment: production |
| 172 | + needs: integration-merge |
| 173 | + if: github.ref == 'refs/heads/staging' |
| 174 | + steps: |
| 175 | + - run: entrypoint |
| 176 | + - uses: actions/checkout@v4 |
| 177 | + with: |
| 178 | + lfs: true |
| 179 | + - uses: actions/download-artifact@v4 |
| 180 | + with: |
| 181 | + name: public |
| 182 | + path: ./public |
| 183 | + - name: Run deployment |
| 184 | + env: |
| 185 | + name: 'production' |
| 186 | + url: 'https://polykey.com/docs/' |
| 187 | + deployment_tier: 'production' |
| 188 | + CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} |
| 189 | + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} |
| 190 | + run: | |
| 191 | + nix develop .#ci --command bash -c $' |
| 192 | + npm run deploy -- --env production |
| 193 | + ' |
0 commit comments