|
| 1 | +# GitHub Actions Workflows |
| 2 | + |
| 3 | +This directory contains the CI/CD workflows for the CloudAMQP CLI. |
| 4 | + |
| 5 | +## Workflows |
| 6 | + |
| 7 | +### CI Workflow (`ci.yml`) |
| 8 | + |
| 9 | +Runs on every push to `main` or `develop` branches, and on pull requests. |
| 10 | + |
| 11 | +**What it does:** |
| 12 | +- Tests with multiple Go versions (1.21, 1.22, 1.23) |
| 13 | +- Runs format checks, vet, and tests |
| 14 | +- Builds the binary with version information |
| 15 | +- Uploads test coverage to Codecov |
| 16 | +- Verifies the binary works with `--help` and `version` commands |
| 17 | + |
| 18 | +**Version Information:** |
| 19 | +The CI build automatically includes: |
| 20 | +- Version: From `git describe --tags --always --dirty` (or "dev" as fallback) |
| 21 | +- Build Date: Current date in UTC (YYYY-MM-DD) |
| 22 | +- Git Commit: Short commit hash |
| 23 | + |
| 24 | +### Release Workflow (`release.yml`) |
| 25 | + |
| 26 | +Triggers when a tag starting with `v` is pushed (e.g., `v1.0.0`), or can be run manually. |
| 27 | + |
| 28 | +**What it does:** |
| 29 | +1. **Build Job**: Builds cross-platform binaries for: |
| 30 | + - Linux (amd64, arm64) |
| 31 | + - macOS (amd64, arm64) |
| 32 | + - Windows (amd64, arm64) |
| 33 | + |
| 34 | +2. **Package Job**: Creates release archives: |
| 35 | + - `.tar.gz` for Linux/macOS binaries |
| 36 | + - `.zip` for Windows binaries |
| 37 | + - Creates GitHub Release with all artifacts |
| 38 | + |
| 39 | +**Version Information:** |
| 40 | +Release builds automatically include: |
| 41 | +- Version: From the git tag (e.g., `v1.0.0`) |
| 42 | +- Build Date: Current date in UTC (YYYY-MM-DD) |
| 43 | +- Git Commit: Short commit hash |
| 44 | + |
| 45 | +The version info is embedded using Go's `-ldflags`: |
| 46 | +```bash |
| 47 | +-ldflags="-w -s -X cloudamqp-cli/cmd.Version=$VERSION -X cloudamqp-cli/cmd.BuildDate=$BUILD_DATE -X cloudamqp-cli/cmd.GitCommit=$GIT_COMMIT" |
| 48 | +``` |
| 49 | + |
| 50 | +## Creating a Release |
| 51 | + |
| 52 | +To create a new release: |
| 53 | + |
| 54 | +1. **Create and push a tag:** |
| 55 | + ```bash |
| 56 | + git tag v1.0.0 |
| 57 | + git push origin v1.0.0 |
| 58 | + ``` |
| 59 | + |
| 60 | +2. The release workflow will automatically: |
| 61 | + - Build binaries for all platforms |
| 62 | + - Create archives |
| 63 | + - Create a GitHub release with auto-generated release notes |
| 64 | + - Upload all artifacts |
| 65 | + |
| 66 | +3. The released binaries will show proper version info: |
| 67 | + ```bash |
| 68 | + $ cloudamqp version |
| 69 | + cloudamqp version v1.0.0 (2025-11-26) |
| 70 | + https://github.com/cloudamqp/cli/releases/tag/v1.0.0 |
| 71 | + ``` |
| 72 | + |
| 73 | +## Manual Workflow Trigger |
| 74 | + |
| 75 | +The release workflow can also be triggered manually from the GitHub Actions UI: |
| 76 | +1. Go to Actions tab |
| 77 | +2. Select "Build Release" workflow |
| 78 | +3. Click "Run workflow" |
| 79 | +4. Select branch and click "Run workflow" |
| 80 | + |
| 81 | +## Verification |
| 82 | + |
| 83 | +Both workflows include verification steps: |
| 84 | +- **CI**: Tests the built binary with `--help` and `version` commands |
| 85 | +- **Release**: Attempts to run `version` command on non-Windows binaries (may skip for cross-compiled binaries) |
| 86 | + |
| 87 | +## Caching |
| 88 | + |
| 89 | +Both workflows use Go module caching to speed up builds: |
| 90 | +- Cache key includes Go version and `go.sum` hash |
| 91 | +- Cached paths: `~/.cache/go-build` and `~/go/pkg/mod` |
| 92 | + |
| 93 | +## Build Flags |
| 94 | + |
| 95 | +**CI builds:** |
| 96 | +- Standard build flags |
| 97 | +- Version information included |
| 98 | + |
| 99 | +**Release builds:** |
| 100 | +- `-a`: Force rebuilding of packages |
| 101 | +- `-installsuffix cgo`: Use suffix for cgo-enabled builds |
| 102 | +- `-ldflags="-w -s"`: Strip debug info and symbol tables (smaller binaries) |
| 103 | +- Version information via `-X` flags |
| 104 | +- `CGO_ENABLED=0`: Disable cgo for static binaries |
| 105 | + |
| 106 | +## Artifacts |
| 107 | + |
| 108 | +**CI Workflow:** |
| 109 | +- Uploads test coverage to Codecov |
| 110 | + |
| 111 | +**Release Workflow:** |
| 112 | +- Individual binaries (30 days retention) |
| 113 | +- Release archives (90 days retention) |
| 114 | +- GitHub Release assets (permanent) |
| 115 | + |
| 116 | +## Troubleshooting |
| 117 | + |
| 118 | +If version information is not showing correctly in releases: |
| 119 | + |
| 120 | +1. Check that tags are pushed: `git push origin --tags` |
| 121 | +2. Verify tag format: Must start with `v` (e.g., `v1.0.0`) |
| 122 | +3. Check workflow logs for version extraction step |
| 123 | +4. Ensure no local modifications (avoid `-dirty` in version) |
| 124 | + |
| 125 | +## Local Testing |
| 126 | + |
| 127 | +To test version embedding locally: |
| 128 | + |
| 129 | +```bash |
| 130 | +# Using Make (recommended) |
| 131 | +make build |
| 132 | + |
| 133 | +# Manual |
| 134 | +VERSION=v1.0.0 |
| 135 | +BUILD_DATE=$(date -u +"%Y-%m-%d") |
| 136 | +GIT_COMMIT=$(git rev-parse --short HEAD) |
| 137 | + |
| 138 | +go build -ldflags "\ |
| 139 | + -X cloudamqp-cli/cmd.Version=$VERSION \ |
| 140 | + -X cloudamqp-cli/cmd.BuildDate=$BUILD_DATE \ |
| 141 | + -X cloudamqp-cli/cmd.GitCommit=$GIT_COMMIT" \ |
| 142 | + -o cloudamqp . |
| 143 | +``` |
0 commit comments