Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
chilagrow committed Feb 14, 2025
1 parent 5db2030 commit efd8ea2
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ferretdb_go_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:

# Do not run this job in parallel for any PR change or branch push.
concurrency:
group: ${{ github.workflow }}-short-test-${{ github.head_ref || github.ref_name }}
group: ${{ github.workflow }}-${{ github.head_ref || github.ref_name }}
cancel-in-progress: true

if: github.event_name != 'pull_request' || !contains(github.event.pull_request.labels.*.name, 'not ready')
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ferretdb_packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ name: Packages
on:
pull_request:
types:
- labeled
- unlabeled
- unlabeled # if GitHub Actions stuck, add and remove "not ready" label to force rebuild
- opened
- reopened
- synchronize
push:
branches:
- "*"
- main
- ferretdb
tags:
- "*"
schedule:
Expand Down
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,13 @@
*.idb
*.pdb

# FerretDB packaging
!*go.mod
*.deb
/bin

# Kernel Module Compile Results
*.mod*
!*go.mod
*.cmd
.tmp_versions/
modules.order
Expand All @@ -70,6 +74,3 @@ build/

# temp schedules
*.tmp

# packages
*.deb
2 changes: 1 addition & 1 deletion ferretdb_packaging/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# To Build Your Own Debian Packages With Docker
Run `./ferretdb_packaging/build_packages.sh -h` and follow the instructions.
E.g. to build for Debian 12 and PostgreSQL 16, run:
E.g. to build for Debian 12 and PostgreSQL 16 for 0.100.0 version, run:
```
./ferretdb_packaging/build_packages.sh --os deb12 --pg 16 --version 0.100.0
```
Expand Down
2 changes: 1 addition & 1 deletion ferretdb_packaging/build_packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ function show_help {
echo "Mandatory Arguments:"
echo " --os OS to build packages for. Possible values: [deb11, deb12, ubuntu20.04, ubuntu22.04, ubuntu24.04]"
echo " --pg PG version to build packages for. Possible values: [15, 16]"
echo " --version The debian conformed documentdb version to build. Examples: [0.100.0, 0.100.0~main]"
echo ""
echo "Optional Arguments:"
echo " --version The debian conformed documentdb version to build. Examples: [0.100.0, 0.100.0~pre.main]"
echo " --test-clean-install Test installing the packages in a clean Docker container."
echo " --output-dir Relative path from the repo root of the directory where to drop the packages. The directory will be created if it doesn't exist. Default: packaging"
echo " -h, --help Display this help message."
Expand Down
20 changes: 12 additions & 8 deletions ferretdb_packaging/defineversion/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package main defines debian version number for CI.
package main

import (
Expand Down Expand Up @@ -100,7 +101,9 @@ func controlVersion(f string) (string, error) {
return version, nil
}

// Define extracts Docker image names and tags from the environment variables defined by GitHub Actions.
// Define extracts debian version number from the environment variables defined by GitHub Actions.
// If the release tag was set, it checks the tag matches with the control version
// and returns an error on mismatch.
func define(controlDefaultVersion string, getenv githubactions.GetenvFunc) (string, error) {
version, err := parseVersion(controlDefaultVersion)
if err != nil {
Expand Down Expand Up @@ -151,34 +154,35 @@ func defineForPR(version, branch string) string {
branch = parts[len(parts)-1]
branch = debianVer.ReplaceAllString(branch, "~")

return fmt.Sprintf("%s~pre.pr~%s", version, branch)
return fmt.Sprintf("%s~pr~%s", version, branch)
}

// defineForBranch defines package version for branch builds.
func defineForBranch(version, branch string) (string, error) {
switch branch {
case "main", "ferretdb":
return fmt.Sprintf("%s~pre.%s", version, branch), nil
return fmt.Sprintf("%s~%s", version, branch), nil
default:
return "", fmt.Errorf("unhandled branch %q", branch)
}
}

// defineForTag defines package version for prerelease tag builds.
func defineForTag(version string, tag string) (string, error) {
// defineForTag defines package version for release build.
// It returns an error if tag version does not match the control version.
func defineForTag(controlVersion string, tag string) (string, error) {
tagVersion, err := parseVersion(tag)
if err != nil {
return "", err
}

if tagVersion != version {
return "", fmt.Errorf("version in control file and release tag mismatch control:%s tag:%s", version, tagVersion)
if tagVersion != controlVersion {
return "", fmt.Errorf("version in control file and release tag mismatch control:%s tag:%s", controlVersion, tagVersion)
}

return tagVersion, nil
}

// parseVersion parses the version string in the format `0.100-0` and
// parseVersion parses the version string in the format `0.100-0` or `v0.100-0` and
// returns a normalized version string in `0.100.0` format.
func parseVersion(version string) (string, error) {
match := documentDBVer.FindStringSubmatch(version)
Expand Down
33 changes: 15 additions & 18 deletions ferretdb_packaging/defineversion/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,12 @@ func getEnvFunc(t *testing.T, env map[string]string) func(string) string {
return val
}
}

type testCase struct {
env map[string]string
defaultVersion string // pg_documentdb/documentdb.control file's default_version field
expected string
}

func TestDefine(t *testing.T) {
for name, tc := range map[string]testCase{
for name, tc := range map[string]struct {
env map[string]string
defaultVersion string // pg_documentdb/documentdb.control file's default_version field
expected string
}{
"pull_request": {
env: map[string]string{
"GITHUB_BASE_REF": "main",
Expand All @@ -54,7 +51,7 @@ func TestDefine(t *testing.T) {
"GITHUB_REF_TYPE": "branch",
},
defaultVersion: "0.100-0",
expected: "0.100.0~pre.pr~define~docker~tag",
expected: "0.100.0~pr~define~docker~tag",
},

"pull_request/dependabot": {
Expand All @@ -66,7 +63,7 @@ func TestDefine(t *testing.T) {
"GITHUB_REF_TYPE": "branch",
},
defaultVersion: "0.100-0",
expected: "0.100.0~pre.pr~mongo~go~driver~29d768e",
expected: "0.100.0~pr~mongo~go~driver~29d768e",
},

"pull_request_target": {
Expand All @@ -78,7 +75,7 @@ func TestDefine(t *testing.T) {
"GITHUB_REF_TYPE": "branch",
},
defaultVersion: "0.100-0",
expected: "0.100.0~pre.pr~define~docker~tag",
expected: "0.100.0~pr~define~docker~tag",
},

"push/main": {
Expand All @@ -90,7 +87,7 @@ func TestDefine(t *testing.T) {
"GITHUB_REF_TYPE": "branch",
},
defaultVersion: "0.100-0",
expected: "0.100.0~pre.main",
expected: "0.100.0~main",
},
"push/ferretdb": {
env: map[string]string{
Expand All @@ -101,7 +98,7 @@ func TestDefine(t *testing.T) {
"GITHUB_REF_TYPE": "branch",
},
defaultVersion: "0.100-0",
expected: "0.100.0~pre.ferretdb",
expected: "0.100.0~ferretdb",
},
"push/other": {
env: map[string]string{
Expand Down Expand Up @@ -156,7 +153,7 @@ func TestDefine(t *testing.T) {
"GITHUB_REPOSITORY": "FerretDB/FerretDB",
},
defaultVersion: "0.100-0",
expected: "0.100.0~pre.main",
expected: "0.100.0~main",
},

"workflow_run": {
Expand All @@ -169,7 +166,7 @@ func TestDefine(t *testing.T) {
"GITHUB_REPOSITORY": "FerretDB/FerretDB",
},
defaultVersion: "0.100-0",
expected: "0.100.0~pre.main",
expected: "0.100.0~main",
},
} {
t.Run(name, func(t *testing.T) {
Expand Down Expand Up @@ -203,11 +200,11 @@ func TestResults(t *testing.T) {
})
action := githubactions.New(githubactions.WithGetenv(getenv), githubactions.WithWriter(&stdout))

version := "0.100.0~pre.main"
version := "0.100.0~main"

setResults(action, version)

expected := "version: 0.100.0~pre.main\n"
expected := "version: 0.100.0~main\n"
assert.Equal(t, expected, stdout.String(), "stdout does not match")

b, err := io.ReadAll(summaryF)
Expand All @@ -216,7 +213,7 @@ func TestResults(t *testing.T) {

expectedOutput := `
version<<_GitHubActionsFileCommandDelimeter_
0.100.0~pre.main
0.100.0~main
_GitHubActionsFileCommandDelimeter_
`[1:]
b, err = io.ReadAll(outputF)
Expand Down

0 comments on commit efd8ea2

Please sign in to comment.