CI #692
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| branches: [main] | |
| schedule: | |
| - cron: '0 16 * * *' | |
| jobs: | |
| setup-env: | |
| # Prepare common variables: date, timestamp, repo, and short SHA | |
| runs-on: ubuntu-24.04 | |
| if: github.event_name == 'schedule' || github.event_name == 'push' | |
| outputs: | |
| date: ${{ steps.vars.outputs.date }} | |
| date_time: ${{ steps.vars.outputs.date_time }} | |
| source_date_epoch: ${{ steps.vars.outputs.source_date_epoch }} | |
| repo: ${{ steps.vars.outputs.repo }} | |
| short_sha: ${{ steps.vars.outputs.short_sha }} | |
| steps: | |
| - name: Generate common variables | |
| id: vars | |
| run: | | |
| now=$(date +%s) | |
| date=$(date -u -d "@$now" '+%Y-%m-%d') | |
| date_time=$(date -u -d "@$now" '+%Y-%m-%d.%H-%M-%S') | |
| year_month=$(date -u -d "@$now" '+%Y-%m') | |
| source_date_epoch=$(date -u -d "${year_month}-01 00:00:00" '+%s') | |
| echo "date=$date" >> $GITHUB_OUTPUT | |
| echo "date_time=$date_time" >> $GITHUB_OUTPUT | |
| echo "source_date_epoch=$source_date_epoch" >> $GITHUB_OUTPUT | |
| echo "repo=${GITHUB_REPOSITORY,,}" >> $GITHUB_OUTPUT | |
| echo "short_sha=${GITHUB_SHA:0:8}" >> $GITHUB_OUTPUT | |
| build-matrix: | |
| needs: setup-env | |
| runs-on: ${{ matrix.runner }} | |
| strategy: | |
| matrix: | |
| include: | |
| - platform: amd64 | |
| runner: ubuntu-24.04 | |
| - platform: arm64 | |
| runner: ubuntu-24.04-arm | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Cache Go modules | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.cache/go-build | |
| key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | |
| restore-keys: | | |
| ${{ runner.os }}-go- | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.24' | |
| check-latest: true | |
| - name: Install dependencies | |
| run: go mod download | |
| - name: Run tests | |
| run: go test ./... | |
| - name: Build static binary | |
| env: | |
| CGO_ENABLED: 0 | |
| GOOS: linux | |
| GOARCH: ${{ matrix.platform }} | |
| SOURCE_DATE_EPOCH: ${{ needs.setup-env.outputs.source_date_epoch }} | |
| run: | | |
| mkdir -p build | |
| go build -ldflags="-s -w -buildid= " -o build/promptpipe-${{ matrix.platform }} ./cmd/PromptPipe | |
| - name: Upload built binary | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: binaries-${{ matrix.platform }} | |
| path: build/promptpipe-${{ matrix.platform }} | |
| docker-build: | |
| needs: [setup-env, build-matrix] | |
| runs-on: ubuntu-24.04 | |
| if: github.event_name == 'schedule' || (github.event_name == 'push' && contains(github.event.head_commit.message, 'run-ci')) | |
| permissions: | |
| packages: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Download amd64 binary | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: binaries-amd64 | |
| path: docker/artifacts | |
| - name: Download arm64 binary | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: binaries-arm64 | |
| path: docker/artifacts | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v2 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and push multi-arch image | |
| uses: docker/build-push-action@v6 | |
| env: | |
| SOURCE_DATE_EPOCH: ${{ needs.setup-env.outputs.source_date_epoch }} | |
| with: | |
| context: docker | |
| file: docker/Dockerfile | |
| platforms: linux/amd64,linux/arm64 | |
| tags: | | |
| ghcr.io/${{ needs.setup-env.outputs.repo }}:latest | |
| ghcr.io/${{ needs.setup-env.outputs.repo }}:${{ needs.setup-env.outputs.date }} | |
| ghcr.io/${{ needs.setup-env.outputs.repo }}:${{ needs.setup-env.outputs.date }}.${{ needs.setup-env.outputs.short_sha }} | |
| ghcr.io/${{ needs.setup-env.outputs.repo }}:${{ needs.setup-env.outputs.date_time }} | |
| ghcr.io/${{ needs.setup-env.outputs.repo }}:${{ needs.setup-env.outputs.date_time }}.${{ needs.setup-env.outputs.short_sha }} | |
| outputs: "type=registry,compression=zstd,force-compression=true,compression-level=3,rewrite-timestamp=true,oci-mediatypes=true" | |
| release: | |
| needs: [setup-env, build-matrix] | |
| runs-on: ubuntu-24.04 | |
| if: github.event_name == 'schedule' || (github.event_name == 'push' && contains(github.event.head_commit.message, 'run-ci')) | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Download amd64 binary | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: binaries-amd64 | |
| path: release/artifacts | |
| - name: Download arm64 binary | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: binaries-arm64 | |
| path: release/artifacts | |
| - name: Set release version | |
| id: version | |
| run: | | |
| ver="${{ needs.setup-env.outputs.date_time }}.${{ needs.setup-env.outputs.short_sha }}" | |
| echo "version=$ver" >> $GITHUB_OUTPUT | |
| - name: Create or update GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ steps.version.outputs.version }} | |
| target_commitish: ${{ github.sha }} | |
| files: | | |
| release/artifacts/* |