Skip to content

Commit 9c51bc1

Browse files
committed
ci: redesign pipeline with security hardening and best practices
Pipeline redesign: - Split into test, build, release, publish jobs with clear responsibilities - test: go tests + coverage reporting - build: nix matrix build (x86_64-linux, aarch64-darwin) with artifact upload - release: release-please PR management - publish: download artifacts and upload to GitHub release Security hardening: - Move all permissions to job level (least privilege) - Restrict merge.yml from write-all to contents+pull-requests write - Add concurrency control with cancel-in-progress for PRs - Add job timeouts across all workflows Workflow improvements: - Replace github-script auto-merge with gh CLI (approve + merge --auto) - Restrict auto-merge trigger to opened/reopened events only - Add LGTM body to approval review - Set dependabot[bot] as flake.lock PR author for auto-merge compatibility - Add conventional commit message and PR title to flake.lock updates - Add defaults: run: shell: bash to ci.yml and merge.yml - Set use-flakehub: disabled and use-gha-cache: enabled on magic-nix-cache - Use upload-artifact@v7 with archive: false and if-no-files-found: error - Use download-artifact@v8 with skip-decompress: true and merge-multiple: true - Add fail-fast: false to build matrix - Group dependabot updates to reduce PR noise - Move fetch-depth: 0 to release job only Nix: - Add doInstallCheck + installCheckPhase for smoke test on nix build Coverage: - Drop octocov push/report (Option B): remove generated badge.svg and report.json from repo, keep only PR comment reporting - Remove stale coverage badge from README
1 parent b3943c1 commit 9c51bc1

8 files changed

Lines changed: 123 additions & 90 deletions

File tree

.github/dependabot.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ updates:
66
schedule:
77
interval: "weekly"
88
open-pull-requests-limit: 10
9+
groups:
10+
all-go-deps:
11+
patterns: ["*"]
912
labels:
1013
- "dependencies"
1114
- "go"
@@ -19,6 +22,9 @@ updates:
1922
schedule:
2023
interval: "weekly"
2124
open-pull-requests-limit: 10
25+
groups:
26+
all-actions:
27+
patterns: ["*"]
2228
labels:
2329
- "dependencies"
2430
- "github-actions"

.github/octocov/badge.svg

Lines changed: 0 additions & 24 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 83 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,65 @@
11
name: CI
22

3-
permissions:
4-
contents: write
5-
id-token: write
6-
pull-requests: write
7-
83
on:
94
push:
105
branches: [main]
116
pull_request:
127
branches: [main]
138

9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
12+
13+
defaults:
14+
run:
15+
shell: bash
16+
1417
jobs:
15-
build:
18+
test:
1619
runs-on: ubuntu-latest
20+
permissions:
21+
contents: read
22+
pull-requests: write
23+
timeout-minutes: 30
1724
steps:
1825
- name: Checkout
1926
uses: actions/checkout@v6
20-
with:
21-
fetch-depth: 0
2227

2328
- name: Install Nix
2429
uses: DeterminateSystems/nix-installer-action@v22
2530

2631
- name: Setup Nix Cache
2732
uses: DeterminateSystems/magic-nix-cache-action@v13
33+
with:
34+
use-flakehub: disabled
35+
use-gha-cache: enabled
2836

2937
- name: Run Tests
30-
run: nix develop --command go tool ginkgo run -r -coverprofile=coverage.out -covermode=atomic ./...
38+
run: |
39+
nix develop --command go tool ginkgo run -r \
40+
-coverprofile=coverage.out -covermode=atomic ./...
3141
3242
- name: Run octocov
3343
uses: k1LoW/octocov-action@v1
3444
with:
3545
github-token: ${{ secrets.GITHUB_TOKEN }}
3646

37-
release:
38-
needs: build
39-
if: github.event_name == 'push'
40-
runs-on: ubuntu-latest
41-
outputs:
42-
release_created: ${{ steps.release.outputs.release_created }}
43-
tag_name: ${{ steps.release.outputs.tag_name }}
44-
steps:
45-
- name: Checkout
46-
uses: actions/checkout@v6
47-
48-
- name: Create Release PR
49-
id: release
50-
uses: googleapis/release-please-action@v4
51-
with:
52-
manifest-file: .github/config/release-please-manifest.json
53-
config-file: .github/config/release-please-config.json
54-
target-branch: main
55-
56-
build-release:
57-
needs: release
58-
if: ${{ needs.release.outputs.release_created }}
47+
build:
48+
needs: test
5949
strategy:
50+
fail-fast: false
6051
matrix:
6152
include:
6253
- os: ubuntu-latest
6354
nix_system: x86_64-linux
6455
- os: macos-14
6556
nix_system: aarch64-darwin
6657
runs-on: ${{ matrix.os }}
58+
permissions:
59+
contents: read
60+
timeout-minutes: 60
61+
env:
62+
BIN_PATH: sqlc-gen-queries-${{ matrix.nix_system }}
6763
steps:
6864
- name: Checkout
6965
uses: actions/checkout@v6
@@ -73,16 +69,68 @@ jobs:
7369

7470
- name: Setup Nix Cache
7571
uses: DeterminateSystems/magic-nix-cache-action@v13
72+
with:
73+
use-flakehub: disabled
74+
use-gha-cache: enabled
7675

7776
- name: Build with Nix
7877
run: nix build . --system ${{ matrix.nix_system }}
7978

80-
- name: Prepare Release Assets
81-
run: |
82-
mkdir -p release && install -m 0755 result/bin/sqlc-gen-queries release/sqlc-gen-queries-${{ matrix.nix_system }}
79+
- name: Prepare Binary
80+
run: install -m 0755 result/bin/sqlc-gen-queries "$BIN_PATH"
81+
82+
- name: Upload Binary
83+
uses: actions/upload-artifact@v7
84+
with:
85+
path: ${{ env.BIN_PATH }}
86+
archive: false
87+
if-no-files-found: error
88+
retention-days: 1
89+
90+
release:
91+
needs: build
92+
if: github.event_name == 'push'
93+
runs-on: ubuntu-latest
94+
outputs:
95+
release_created: ${{ steps.release.outputs.release_created }}
96+
tag_name: ${{ steps.release.outputs.tag_name }}
97+
permissions:
98+
contents: write
99+
id-token: write
100+
pull-requests: write
101+
timeout-minutes: 15
102+
steps:
103+
- name: Checkout
104+
uses: actions/checkout@v6
105+
with:
106+
fetch-depth: 0
107+
108+
- name: Create Release PR
109+
id: release
110+
uses: googleapis/release-please-action@v4
111+
with:
112+
manifest-file: .github/config/release-please-manifest.json
113+
config-file: .github/config/release-please-config.json
114+
target-branch: main
115+
116+
publish:
117+
needs: release
118+
if: needs.release.outputs.release_created
119+
runs-on: ubuntu-latest
120+
permissions:
121+
contents: write
122+
timeout-minutes: 10
123+
steps:
124+
- name: Download Binaries
125+
uses: actions/download-artifact@v8
126+
with:
127+
pattern: sqlc-gen-queries-*
128+
merge-multiple: true
129+
skip-decompress: true
130+
path: release/
83131

84132
- name: Upload Release Assets
85133
uses: softprops/action-gh-release@v3
86134
with:
87135
tag_name: ${{ needs.release.outputs.tag_name }}
88-
files: release/sqlc-gen-queries-${{ matrix.nix_system }}
136+
files: release/*

.github/workflows/merge.yml

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,25 @@ name: Auto Merge
22

33
on:
44
pull_request:
5+
types: [opened, reopened]
56

6-
permissions: write-all
7+
defaults:
8+
run:
9+
shell: bash
710

811
jobs:
9-
automerge:
10-
if: ${{ github.actor == 'dependabot[bot]' }}
12+
merge:
13+
if: github.actor == 'dependabot[bot]'
1114
runs-on: ubuntu-latest
15+
permissions:
16+
contents: write
17+
pull-requests: write
18+
timeout-minutes: 5
1219
steps:
13-
- name: automerge
14-
uses: actions/github-script@v9.0.0
15-
with:
16-
script: |
17-
github.rest.pulls.createReview({
18-
owner: context.payload.repository.owner.login,
19-
repo: context.payload.repository.name,
20-
pull_number: context.payload.pull_request.number,
21-
event: 'APPROVE'
22-
})
23-
github.rest.pulls.merge({
24-
owner: context.payload.repository.owner.login,
25-
repo: context.payload.repository.name,
26-
pull_number: context.payload.pull_request.number,
27-
merge_method: "rebase",
28-
})
29-
github-token: ${{ github.token }}
20+
- name: Enable auto-merge
21+
env:
22+
GH_TOKEN: ${{ github.token }}
23+
PR_URL: ${{ github.event.pull_request.html_url }}
24+
run: |
25+
gh pr review --approve --body "LGTM" "$PR_URL"
26+
gh pr merge --auto --squash "$PR_URL"

.github/workflows/update.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ on:
55
- cron: "0 0 * * 1"
66
workflow_dispatch:
77

8-
permissions:
9-
contents: write
10-
pull-requests: write
11-
128
jobs:
139
update:
1410
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
pull-requests: write
14+
timeout-minutes: 30
1515
steps:
1616
- name: Checkout
1717
uses: actions/checkout@v6
@@ -21,8 +21,17 @@ jobs:
2121

2222
- name: Setup Nix Cache
2323
uses: DeterminateSystems/magic-nix-cache-action@v13
24+
with:
25+
use-flakehub: disabled
26+
use-gha-cache: enabled
2427

2528
- name: Update root flake.lock
2629
uses: DeterminateSystems/update-flake-lock@v28
2730
with:
2831
pr-labels: dependencies
32+
pr-title: "chore(flake): update flake.lock"
33+
commit-msg: "chore(flake): update flake.lock"
34+
git-author-name: dependabot[bot]
35+
git-author-email: dependabot[bot]@users.noreply.github.com
36+
git-committer-name: dependabot[bot]
37+
git-committer-email: dependabot[bot]@users.noreply.github.com

.octocov.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,3 @@ comment:
99
deletePrevious: true
1010
summary:
1111
if: true
12-
report:
13-
if: is_default_branch
14-
path: .github/octocov/report.json
15-
push:
16-
if: is_default_branch
17-
message: Update by octocov [skip ci]

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
[![License](https://img.shields.io/github/license/sqlc-contrib/sqlc-gen-queries)](LICENSE)
66
[![Go](https://img.shields.io/badge/Go-1.25-00ADD8?logo=go&logoColor=white)](https://go.dev)
77
[![sqlc](https://img.shields.io/badge/sqlc-compatible-blue)](https://sqlc.dev)
8-
[![Coverage](https://raw.githubusercontent.com/sqlc-contrib/sqlc-gen-queries/main/.github/octocov/badge.svg)](https://github.com/sqlc-contrib/sqlc-gen-queries/actions/workflows/ci.yml)
98

109
A CLI tool that generates [sqlc](https://sqlc.dev)-compatible SQL queries from your database schema catalog. Point it at a schema catalog and a configuration file, and it produces ready-to-use query files for sqlc.
1110

flake.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
src = pkgs.lib.cleanSource ./.;
2222
subPackages = [ "cmd/sqlc-gen-queries" ];
2323
vendorHash = "sha256-XyCIXLDH378M+MDyNj0OiBU7bilbF7DzEpA85fNOCGE=";
24+
doInstallCheck = true;
25+
installCheckPhase = ''
26+
$out/bin/sqlc-gen-queries --help
27+
'';
2428
meta = with pkgs.lib; {
2529
description = "SQLC Queries Generator";
2630
license = licenses.mit;

0 commit comments

Comments
 (0)