|
| 1 | +# GitHub Actions Workflows Documentation |
| 2 | + |
| 3 | +This directory contains GitHub Actions workflows for CI/CD automation of the `concourse-netbox-resource` project. The workflows provide code validation, image building and release management. |
| 4 | + |
| 5 | +## TOC |
| 6 | +- [GitHub Actions Workflows Documentation](#github-actions-workflows-documentation) |
| 7 | + - [TOC](#toc) |
| 8 | + - [Overview](#overview) |
| 9 | + - [Workflow Details](#workflow-details) |
| 10 | + - [Validate Code Workflow](#validate-code-workflow) |
| 11 | + - [Jobs and Steps](#jobs-and-steps) |
| 12 | + - [Build Image Workflow](#build-image-workflow) |
| 13 | + - [Jobs and Steps](#jobs-and-steps-1) |
| 14 | + - [Publish Release Workflow](#publish-release-workflow) |
| 15 | + - [Jobs and Steps](#jobs-and-steps-2) |
| 16 | + - [Environment Variables](#environment-variables) |
| 17 | + - [Container Images](#container-images) |
| 18 | + - [Workflow vizualization](#workflow-vizualization) |
| 19 | + - [Release Process](#release-process) |
| 20 | + - [Dependencies](#dependencies) |
| 21 | + |
| 22 | +## Overview |
| 23 | + |
| 24 | +The project uses three main workflows that work together to ensure code quality and automate releases: |
| 25 | + |
| 26 | +| | | |
| 27 | +| :--- | :--- | |
| 28 | +| [Validate Code workflow](#validate-code-workflow) | Validates code quality on feature branches | |
| 29 | +| [Build Image workflow](#build-image-workflow) | Builds draft releases when tags are pushed | |
| 30 | +| [Publish Release workflow](#publish-release-workflow) | Publishes final releases when merged to master | |
| 31 | + |
| 32 | +## Workflow Details |
| 33 | + |
| 34 | +### Validate Code Workflow |
| 35 | + |
| 36 | +| | | |
| 37 | +| :--- | :--- | |
| 38 | +| **File** | [`validate-code.yaml`](./validate-code.yaml) | |
| 39 | +| **Trigger** | Push to any branch except `master` | |
| 40 | +| **Purpose** | Ensures code quality by running tests | |
| 41 | + |
| 42 | +#### Jobs and Steps |
| 43 | +- **validateCode:** |
| 44 | + - Checks out code |
| 45 | + - Populates environment variables (`GIT_COMMIT`, `GIT_TAG`, `BUILD_DATE`, `LDFLAGS`, `GO_VERSION`) |
| 46 | + - Sets up Go using the version from [go.mod](../../go.mod) |
| 47 | + - Runs [golangci-lint](https://github.com/golangci/golangci-lint) for static code analysis |
| 48 | + - Runs [govulncheck](https://pkg.go.dev/golang.org/x/vuln/cmd/govulncheck) for vulnerability scanning |
| 49 | + - Executes unit tests and showing the coverage ratio |
| 50 | + - Builds all three binaries (`check`, `in`, `out`) |
| 51 | + - Validates that built binaries report correct version information |
| 52 | + |
| 53 | +### Build Image Workflow |
| 54 | + |
| 55 | +| | | |
| 56 | +| :--- | :--- | |
| 57 | +| **File** | [`build-image.yaml`](./build-image.yaml) | |
| 58 | +| **Trigger** | Push to tags matching `v*` pattern | |
| 59 | +| **Purpose** | Creates a draft release pointing to the container image | |
| 60 | + |
| 61 | +#### Jobs and Steps |
| 62 | +- **validateCode:** |
| 63 | + - same as in [Validate Code Workflow](#validate-code-workflow) |
| 64 | + - Additional validation to ensure a valid git tag exists |
| 65 | + |
| 66 | +- **buildImage:** |
| 67 | + - depends on the `validateCode` job |
| 68 | + - Logs into GitHub Container Registry (GHCR) |
| 69 | + - Generates Docker metadata with multiple tag strategies: |
| 70 | + - semantic versioning (`v1.2.3`, `v1.2`) |
| 71 | + - draft tag |
| 72 | + - date based |
| 73 | + - Builds and pushes `linux/amd64` Docker image |
| 74 | + - Injects build arguments (`GO_VERSION`, `GIT_COMMIT`, `GIT_TAG`, `BUILD_DATE`) |
| 75 | + |
| 76 | +- **createRelease:** |
| 77 | + - depends on the `buildImage` job |
| 78 | + - uses [mdq](https://github.com/yshavit/mdq) to extract the relevant changelog section for the tag |
| 79 | + - Appends Docker pull command to changelog |
| 80 | + - Creates a **draft** GitHub release with the processed changelog |
| 81 | + |
| 82 | +### Publish Release Workflow |
| 83 | + |
| 84 | +| | | |
| 85 | +| :--- | :--- | |
| 86 | +| **File** | [`publish-release.yaml`](./publish-release.yaml) | |
| 87 | +| **Trigger** | Push to `master` branch | |
| 88 | +| **Purpose** | Publishes the release | |
| 89 | + |
| 90 | +#### Jobs and Steps |
| 91 | +- **buildImage:** |
| 92 | + - Similar to build-image workflow but with key differences: |
| 93 | + - Uses `release` tag instead of `draft` |
| 94 | + - Requires an existing git tag on the commit |
| 95 | + |
| 96 | +- **createRelease:** |
| 97 | + - depends on the `buildImage` job |
| 98 | + - Same changelog processing as in the [Build Image workflow](#build-image-workflow) |
| 99 | + - Removes draft status from the release to publish it |
| 100 | + - Updates existing releases only if they are unreleased |
| 101 | + |
| 102 | +## Environment Variables |
| 103 | + |
| 104 | +All workflows populate and use these key environment variables: |
| 105 | + |
| 106 | +| Variable | Description | Example | |
| 107 | +|----------|-------------|---------| |
| 108 | +| `GIT_COMMIT` | Current commit SHA | `abc123def456...` | |
| 109 | +| `GIT_TAG` | Git tag pointing to commit | `v1.2.3` or `undefined` | |
| 110 | +| `BUILD_DATE` | UTC timestamp in RFC3339 format | `2024-01-15T10:30:00Z` | |
| 111 | +| `GO_VERSION` | Go version from go.mod | `1.25.1` | |
| 112 | +| `LDFLAGS` | Linker flags for version injection | `-X 'pkg/helper.gitCommit=...'` | |
| 113 | + |
| 114 | +## Container Images |
| 115 | + |
| 116 | +Images are built and pushed to GitHub Container Registry (GHCR) with the following naming pattern: |
| 117 | + |
| 118 | +| | | |
| 119 | +| :--- | :--- | |
| 120 | +| **Draft release** | `ghcr.io/sapcc/concourse-netbox-resource:draft` | |
| 121 | +| **Published release** | `ghcr.io/sapcc/concourse-netbox-resource:release` | |
| 122 | +| **Semantic version** | `ghcr.io/sapcc/concourse-netbox-resource:v1.2.3` | |
| 123 | +| **Timestamp** | `ghcr.io/sapcc/concourse-netbox-resource:YYYYMMDD-hhmmss` | |
| 124 | +| **Latest** | `ghcr.io/sapcc/concourse-netbox-resource:latest` | |
| 125 | +| **Branch** | `ghcr.io/sapcc/concourse-netbox-resource:branch_name` | |
| 126 | + |
| 127 | +## Workflow vizualization |
| 128 | + |
| 129 | +```mermaid |
| 130 | +flowchart TB |
| 131 | + subgraph "Workflows" |
| 132 | + subgraph A[validate-code.yaml] |
| 133 | + D |
| 134 | + end |
| 135 | +
|
| 136 | + subgraph B[build-image.yaml] |
| 137 | + E --> F --> G |
| 138 | + end |
| 139 | +
|
| 140 | + subgraph C[publish-release.yaml] |
| 141 | + H --> I |
| 142 | + end |
| 143 | + end |
| 144 | +
|
| 145 | + subgraph "Github Registry" |
| 146 | + F --> CID |
| 147 | + H --> CIR |
| 148 | + end |
| 149 | +
|
| 150 | + subgraph "Github Releases" |
| 151 | + G --> DR |
| 152 | + I --> PR |
| 153 | + end |
| 154 | +
|
| 155 | + U --Push to feature branch--> D |
| 156 | + U --Push version tag--> E |
| 157 | + U --Approve & Merge PR--> H |
| 158 | +
|
| 159 | + D([validateCode job]) |
| 160 | + E([validateCode job]) |
| 161 | + F([buildImage job]) |
| 162 | + G([createRelease job]) |
| 163 | + H([buildImage job]) |
| 164 | + I([createRelease job]) |
| 165 | + U(Developer) |
| 166 | + CID@{ shape: div-rect, label: "Draft container image" } |
| 167 | + CIR@{ shape: div-rect, label: "Published container image" } |
| 168 | + DR@{ shape: lin-rect, label: "Draft Release" } |
| 169 | + PR@{ shape: lin-rect, label: "Published Release" } |
| 170 | +``` |
| 171 | + |
| 172 | +## Release Process |
| 173 | + |
| 174 | +The complete release process follows this flow: |
| 175 | + |
| 176 | +1. **Development:** |
| 177 | + - Work on feature branches, all pushes trigger the [Validate Code workflow](#validate-code-workflow) |
| 178 | +2. **Tag Creation:** |
| 179 | + - Create a version tag (e.g., `v1.2.3`) which triggers the [Build Image workflow](#build-image-workflow) |
| 180 | + - Builds and pushes container image with draft tags |
| 181 | + - Creates draft release |
| 182 | +3. **PR Review:** |
| 183 | + - Review and approve the pull request |
| 184 | +4. **Merge:** |
| 185 | + - Merge the approved changes to the `master` branch |
| 186 | + - this triggers the [Publish Release workflow](#publish-release-workflow) |
| 187 | + - Builds and pushes container image with release tags |
| 188 | + - Publishes the release (removes draft status) |
| 189 | + |
| 190 | +## Dependencies |
| 191 | + |
| 192 | +- **Actions Used:** |
| 193 | + - `actions/[email protected]` - Code checkout |
| 194 | + - `actions/[email protected]` - Go environment setup |
| 195 | + - `golangci/[email protected]` - Static analysis |
| 196 | + - `docker/[email protected]` - Container registry authentication |
| 197 | + - `docker/[email protected]` - Docker metadata generation |
| 198 | + - `docker/[email protected]` - Container building and pushing |
| 199 | + - `ncipollo/[email protected]` - GitHub release creation |
| 200 | + |
| 201 | +- **External Tools:** |
| 202 | + - [golangci-lint](https://github.com/golangci/golangci-lint) for static code analysis |
| 203 | + - [govulncheck](https://pkg.go.dev/golang.org/x/vuln/cmd/govulncheck) Go vulnerability scanner |
| 204 | + - [mdq](https://github.com/yshavit/mdq) Markdown query tool for changelog processing |
0 commit comments