Skip to content

Commit 7a552f0

Browse files
committed
workflows simplified
- tag based on changelog - separate validation workflow removed - only one job per workflow - README updated
1 parent f55806c commit 7a552f0

File tree

6 files changed

+184
-342
lines changed

6 files changed

+184
-342
lines changed

.github/workflows/README.md

Lines changed: 107 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ This directory contains GitHub Actions workflows for CI/CD automation of the `co
77
- [TOC](#toc)
88
- [Overview](#overview)
99
- [Workflow Details](#workflow-details)
10-
- [Validate Code Workflow](#validate-code-workflow)
11-
- [Jobs and Steps](#jobs-and-steps)
1210
- [Build Image Workflow](#build-image-workflow)
13-
- [Jobs and Steps](#jobs-and-steps-1)
11+
- [Jobs and Steps](#jobs-and-steps)
1412
- [Publish Release Workflow](#publish-release-workflow)
15-
- [Jobs and Steps](#jobs-and-steps-2)
13+
- [Jobs and Steps](#jobs-and-steps-1)
1614
- [Environment Variables](#environment-variables)
1715
- [Container Images](#container-images)
1816
- [Workflow vizualization](#workflow-vizualization)
@@ -21,171 +19,174 @@ This directory contains GitHub Actions workflows for CI/CD automation of the `co
2119

2220
## Overview
2321

24-
The project uses three main workflows that work together to ensure code quality and automate releases:
22+
The project uses two main workflows that work together to ensure code quality and automate releases:
2523

2624
| | |
2725
| :--- | :--- |
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 |
26+
| [Build Image workflow](#build-image-workflow) | Validates code and builds draft images on feature branches |
27+
| [Publish Release workflow](#publish-release-workflow) | Builds images and publishes releases when merged to master |
3128

3229
## Workflow Details
3330

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-
5331
### Build Image Workflow
5432

5533
| | |
5634
| :--- | :--- |
5735
| **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 |
36+
| **Trigger** | Push to any branch except `master`, excluding `.github` paths |
37+
| **Purpose** | Validates code quality, builds draft container image, and ensures version consistency |
6038

6139
#### 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-
6640
- **buildImage:**
67-
- depends on the `validateCode` job
41+
- Checks out code with full history (fetch-depth: 0)
42+
- Installs [mdq](https://github.com/yshavit/mdq) tool for changelog parsing
43+
- Populates environment variables:
44+
- `BUILD_DATE` - Current UTC timestamp
45+
- `GIT_COMMIT` - Current commit SHA
46+
- `GIT_TAG` - Version extracted from CHANGELOG.md
47+
- `LDFLAGS` - Go linker flags for version injection
48+
- `GO_VERSION` - Go version from go.mod
49+
- Validates environment variables:
50+
- Verifies version format matches `X.Y.Z` pattern (e.g., `1.2.3`)
51+
- Checks that the git tag doesn't already exist
52+
- Sets up Go using version from go.mod
53+
- Runs [golangci-lint](https://github.com/golangci/golangci-lint) v2.4.0 for static code analysis
54+
- Runs [govulncheck](https://pkg.go.dev/golang.org/x/vuln/cmd/govulncheck) for vulnerability scanning
55+
- Executes unit tests with coverage reporting
56+
- Builds the `check` binary with version information
57+
- Validates that built binary reports correct version for all commands (`check`, `in`, `out`)
6858
- 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
59+
- Generates Docker metadata with tags:
60+
- Version tag (e.g., `1.2.3`)
61+
- `draft` tag
62+
- Builds and pushes `linux/amd64` Docker image with build arguments:
63+
- `BUILDER_VERSION` - Go builder image version
64+
- `GIT_COMMIT` - Current commit SHA
65+
- `GIT_TAG` - Version from changelog
66+
- `BUILD_DATE` - Build timestamp
8167

8268
### Publish Release Workflow
8369

8470
| | |
8571
| :--- | :--- |
8672
| **File** | [`publish-release.yaml`](./publish-release.yaml) |
87-
| **Trigger** | Push to `master` branch |
88-
| **Purpose** | Publishes the release |
73+
| **Trigger** | Push to `master` branch, excluding `.github` paths |
74+
| **Purpose** | Builds the release container image, publishes a Github release and creates git tag |
8975

9076
#### 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-
9677
- **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
78+
- Checks out code
79+
- Installs [mdq](https://github.com/yshavit/mdq) tool for changelog parsing
80+
- Populates environment variables:
81+
- `GIT_TAG` - Version extracted from CHANGELOG.md
82+
- `GIT_COMMIT` - Current commit SHA
83+
- Validates environment variables:
84+
- Verifies version format matches `X.Y.Z` pattern
85+
- Checks that the git tag doesn't already exist
86+
- Sets up Go using version from go.mod
87+
- Logs into GitHub Container Registry (GHCR)
88+
- Generates Docker metadata with tags:
89+
- version tag (e.g., `1.2.3`)
90+
- `release` tag
91+
- `latest` tag
92+
- Builds and pushes `linux/amd64` Docker image with build argument:
93+
- `BUILDER_VERSION` - Go builder image version
94+
- `GIT_COMMIT` - Current commit SHA
95+
- `GIT_TAG` - Version from changelog
96+
- `BUILD_DATE` - Build timestamp
97+
- Processes changelog:
98+
- Extracts changelog section for the current version using mdq
99+
- Appends Docker pull command to changelog
100+
- Creates GitHub release using [ncipollo/release-action](https://github.com/ncipollo/release-action):
101+
- Uses processed changelog as release body
102+
- Sets `makeLatest: "legacy"` for latest release handling
103+
- Skips if release already exists
104+
- Updates only unreleased releases
105+
- Creates and pushes git tag:
106+
- Configures git user
107+
- Creates annotated tag with changelog content
108+
- Pushes tag to origin
101109

102110
## Environment Variables
103111

104-
All workflows populate and use these key environment variables:
112+
The workflows populate and use these key environment variables:
105113

106114
| Variable | Description | Example |
107115
|----------|-------------|---------|
108116
| `GIT_COMMIT` | Current commit SHA | `abc123def456...` |
109-
| `GIT_TAG` | Git tag pointing to commit | `v1.2.3` or `undefined` |
117+
| `GIT_TAG` | Version extracted from CHANGELOG.md | `1.2.3` |
110118
| `BUILD_DATE` | UTC timestamp in RFC3339 format | `2024-01-15T10:30:00Z` |
111119
| `GO_VERSION` | Go version from go.mod | `1.25.1` |
112-
| `LDFLAGS` | Linker flags for version injection | `-X 'pkg/helper.gitCommit=...'` |
120+
| `LDFLAGS` | Linker flags for version injection | `-X 'github.com/sapcc/concourse-netbox-resource/internal/helper.gitCommit=...'` |
113121

114122
## Container Images
115123

116-
Images are built and pushed to GitHub Container Registry (GHCR) with the following naming pattern:
124+
Images are built and pushed to GitHub Container Registry (GHCR) with the following tags:
117125

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+
| Tag | Description | Workflow |
127+
| :--- | :--- | :--- |
128+
| `ghcr.io/sapcc/concourse-netbox-resource:draft` | Draft image from feature branches | Build Image |
129+
| `ghcr.io/sapcc/concourse-netbox-resource:release` | Released image from master | Publish Release |
130+
| `ghcr.io/sapcc/concourse-netbox-resource:1.2.3` | Semantic version tag | Both |
131+
132+
All images are built for the `linux/amd64` platform.
126133

127134
## Workflow vizualization
128135

129136
```mermaid
130137
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+
subgraph "Workflows"
139+
subgraph A[build-image.yaml]
140+
D
138141
end
139142
140-
subgraph C[publish-release.yaml]
141-
H --> I
143+
subgraph B[publish-release.yaml]
144+
E
142145
end
143146
end
144147
145-
subgraph "Github Registry"
146-
F --> CID
147-
H --> CIR
148+
subgraph "Github Container Registry"
149+
D --> CID
150+
E --> CIR
148151
end
149152
150-
subgraph "Github Releases"
151-
G --> DR
152-
I --> PR
153+
subgraph "Github Releases & Tags"
154+
E --> PR
155+
E --> GT
153156
end
154157
155158
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])
159+
U --Merge PR to master--> E
160+
161+
D([buildImage job])
162+
E([createRelease job])
165163
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" }
164+
CID@{ shape: div-rect, label: "Draft container image\n(draft, X.Y.Z)" }
165+
CIR@{ shape: div-rect, label: "Release container image\n(latest, release, X.Y.Z)" }
169166
PR@{ shape: lin-rect, label: "Published Release" }
167+
GT@{ shape: lin-rect, label: "Git Tag" }
170168
```
171169

172170
## Release Process
173171

174172
The complete release process follows this flow:
175173

176174
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:**
175+
- Work on feature branches
176+
- All pushes to non-master branches trigger the [Build Image workflow](#build-image-workflow)
177+
- This workflow validates code quality, runs tests, and builds a draft container image
178+
- The version is extracted from CHANGELOG.md and validated
179+
180+
2. **PR Review:**
181+
- Create a pull request to merge changes into `master`
183182
- Review and approve the pull request
184-
4. **Merge:**
183+
184+
3. **Merge & Release:**
185185
- 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)
186+
- This triggers the [Publish Release workflow](#publish-release-workflow) which:
187+
- Builds and pushes the release container image
188+
- Creates a GitHub release with the changelog
189+
- Creates and pushes a git tag for the version
189190

190191
## Dependencies
191192

0 commit comments

Comments
 (0)