| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # shellcheck disable=SC2016 |
| 4 | find . -type f -name go.mod | sort | while read -r mod; do |
| 5 | dir="$(dirname "$mod")" |
| 6 | name="$(basename "$dir")" |
| 7 | # get the parent directory when the module is nested semver-style |
| 8 | if [[ "$name" =~ ^v[0-9]+.*$ ]]; then |
| 9 | ver="$(basename "$dir")" |
| 10 | dir="$(dirname "$dir")" |
| 11 | name="$(basename "$dir")-$ver" |
| 12 | fi |
| 13 | |
| 14 | sum="$dir/go.sum" |
| 15 | echo "# auto-generated by scripts/builds. DO NOT EDIT. |
| 16 | name: $name |
| 17 | |
| 18 | on: |
| 19 | push: |
| 20 | branches: |
| 21 | - main |
| 22 | pull_request: |
| 23 | paths: |
| 24 | - $(dirname "$mod" | cut -f2- -d/)/** |
| 25 | - .github/workflows/${name}.yml |
| 26 | |
| 27 | jobs: |
| 28 | build: |
| 29 | strategy: |
| 30 | matrix: |
| 31 | os: [ubuntu-latest, macos-latest, windows-latest] |
| 32 | runs-on: \${{ matrix.os }} |
| 33 | defaults: |
| 34 | run: |
| 35 | working-directory: $(dirname "$mod") |
| 36 | steps: |
| 37 | - uses: actions/checkout@v5 |
| 38 | - uses: actions/setup-go@v6 |
| 39 | with: |
| 40 | go-version-file: $mod |
| 41 | cache: true |
| 42 | cache-dependency-path: $sum |
| 43 | - run: go build -v ./... |
| 44 | - run: go test -race -v ./... |
| 45 | |
| 46 | dependabot: |
| 47 | needs: [build] |
| 48 | runs-on: ubuntu-latest |
| 49 | permissions: |
| 50 | pull-requests: write |
| 51 | contents: write |
| 52 | if: \${{ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request'}} |
| 53 | steps: |
| 54 | - id: metadata |
| 55 | uses: dependabot/fetch-metadata@v2 |
| 56 | with: |
| 57 | github-token: \"\${{ secrets.GITHUB_TOKEN }}\" |
| 58 | - run: | |
| 59 | gh pr review --approve \"\$PR_URL\" |
| 60 | gh pr merge --squash --auto \"\$PR_URL\" |
| 61 | env: |
| 62 | PR_URL: \${{github.event.pull_request.html_url}} |
| 63 | GITHUB_TOKEN: \${{secrets.GITHUB_TOKEN}} |
| 64 | |
| 65 | lint: |
| 66 | uses: charmbracelet/meta/.github/workflows/lint.yml@main |
| 67 | with: |
| 68 | directory: $(dirname "$mod" | cut -f2- -d/) |
| 69 | |
| 70 | coverage: |
| 71 | strategy: |
| 72 | matrix: |
| 73 | go-version: [^1] |
| 74 | os: [ubuntu-latest, windows-latest, macos-latest] |
| 75 | defaults: |
| 76 | run: |
| 77 | working-directory: $(dirname "$mod") |
| 78 | runs-on: \${{ matrix.os }} |
| 79 | env: |
| 80 | GO111MODULE: \"on\" |
| 81 | steps: |
| 82 | - name: Install Go |
| 83 | uses: actions/setup-go@v6 |
| 84 | with: |
| 85 | go-version: \${{ matrix.go-version }} |
| 86 | |
| 87 | - name: Checkout code |
| 88 | uses: actions/checkout@v5 |
| 89 | |
| 90 | - name: Coverage |
| 91 | run: | |
| 92 | go test -race -covermode=atomic -coverprofile='coverage.txt' ./... |
| 93 | |
| 94 | - uses: codecov/codecov-action@v5 |
| 95 | with: |
| 96 | file: ./coverage.txt |
| 97 | token: \${{ secrets.CODECOV_TOKEN }} |
| 98 | |
| 99 | " >"./.github/workflows/${name}.yml" |
| 100 | done |