|
| 1 | +name: CI |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - main |
| 6 | +env: |
| 7 | + PNPM_CACHE_FOLDER: .pnpm-store |
| 8 | +jobs: |
| 9 | + release: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - uses: actions/checkout@v2 |
| 13 | + with: |
| 14 | + fetch-depth: 0 |
| 15 | + - name: Use Node.js 16.x |
| 16 | + uses: actions/setup-node@v2 |
| 17 | + with: |
| 18 | + node-version: 16 |
| 19 | + - uses: actions/cache@v2 |
| 20 | + with: |
| 21 | + path: ${{ env.PNPM_CACHE_FOLDER }} |
| 22 | + key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }} |
| 23 | + restore-keys: | |
| 24 | + ${{ runner.os }}-pnpm- |
| 25 | + - name: Use pnpm |
| 26 | + uses: pnpm/action-setup@v2 |
| 27 | + with: |
| 28 | + version: 6 |
| 29 | + - name: Setup pnpm config |
| 30 | + run: pnpm config set store-dir $PNPM_CACHE_FOLDER |
| 31 | + - name: Install dependencies |
| 32 | + run: pnpm install |
| 33 | + env: |
| 34 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 35 | + - name: Check |
| 36 | + run: pnpm check |
| 37 | + - name: Test |
| 38 | + run: pnpm test |
| 39 | + - name: Build |
| 40 | + run: pnpm build |
| 41 | + - name: Patch |
| 42 | + run: pnpm patch |
| 43 | + - name: Create release pull request or publish to npm |
| 44 | + id: changesets |
| 45 | + uses: changesets/action@v1 |
| 46 | + with: |
| 47 | + commit: "chore: update versions" |
| 48 | + title: Update versions |
| 49 | + publish: pnpm exec changeset publish |
| 50 | + env: |
| 51 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 52 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 53 | + - id: changesets_meta |
| 54 | + name: Build changesets meta |
| 55 | + uses: actions/github-script@v5 |
| 56 | + env: |
| 57 | + PUBLISHED_PACKAGES: ${{ steps.changesets.outputs.publishedPackages }} |
| 58 | + with: |
| 59 | + script: |- |
| 60 | + const output = {}; |
| 61 | + const published = JSON.parse(process.env.PUBLISHED_PACKAGES); |
| 62 | + output['@sql-controller/cli:published'] = false; |
| 63 | + published.forEach(({ name, version }) => { |
| 64 | + const vars = { version, published: true }; |
| 65 | + Object.keys(vars).forEach(n => output[`${name}:${n}`] = vars[n]); |
| 66 | + }); |
| 67 | + console.log(output); |
| 68 | + Object.keys(output).forEach(k => core.setOutput(k, output[k])); |
| 69 | + - id: image_meta |
| 70 | + name: Build image metadata |
| 71 | + uses: docker/metadata-action@v3 |
| 72 | + if: steps.changesets_meta.outputs['@sql-controller/cli:version'] != '' |
| 73 | + with: |
| 74 | + images: ghcr.io/${{ github.repository }} |
| 75 | + tags: |- |
| 76 | + type=schedule |
| 77 | + type=ref,event=branch |
| 78 | + type=ref,event=pr |
| 79 | + type=semver,pattern={{version}},value=v${{ steps.changesets_meta.outputs['@sql-controller/cli:version'] }} |
| 80 | + type=semver,pattern={{major}}.{{minor}},value=v${{ steps.changesets_meta.outputs['@sql-controller/cli:version'] }} |
| 81 | + type=semver,pattern={{major}},value=v${{ steps.changesets_meta.outputs['@sql-controller/cli:version'] }} |
| 82 | + type=sha |
| 83 | + - name: Setup Docker Buildx |
| 84 | + uses: docker/setup-buildx-action@v1 |
| 85 | + - name: Login Docker |
| 86 | + uses: docker/login-action@v1 |
| 87 | + with: |
| 88 | + registry: ghcr.io |
| 89 | + username: ${{ github.actor }} |
| 90 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 91 | + - name: Build and publish image |
| 92 | + uses: docker/build-push-action@v2 |
| 93 | + with: |
| 94 | + tags: ${{ steps.image_meta.outputs.tags }} |
| 95 | + labels: ${{ steps.image_meta.outputs.labels }} |
| 96 | + push: ${{ steps.changesets_meta.outputs['@sql-controller/cli:published'] }} |
0 commit comments