-
Notifications
You must be signed in to change notification settings - Fork 7
Track changes from upstream #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
d6794c9
fc8f917
8a85bdd
dfb4bdb
3cfbfa1
04821c5
299aa44
aa9b69f
9e6fe15
39ec23d
ee54dd9
64e4625
d468b9b
f7539ee
9bca0e3
8fe5219
d682564
4063590
c9c13d6
46b3f5a
99efe6b
8d0e808
92eb372
9e96940
6b1b7c3
e19f7d7
bf0ebfa
aa5e310
a69b743
6092471
696c433
f7c318c
8366073
b5ed892
4aa45ff
b8cd669
9129ad5
34064ee
2cd740b
9c521eb
80462f5
48cf934
6106bc9
0122a0a
ce33455
e4c2258
5ce0666
da61790
c1a5115
c501656
ac578a4
445037d
7486bb9
73c2395
d89f70b
9efcabf
b66a82b
71802fc
bfc0b31
8a9e2d4
80c8861
149841b
0e64853
ab79acf
f838c59
d4de5a3
2b0e6f9
9492778
d321a1c
fa129dc
dc41469
859432a
7514232
c45681d
560b14b
aa58f47
9b65832
4de83a0
c2757ae
26da990
2045d0e
1190e10
21016ff
2e4bd56
601ec8a
7df4500
166d11e
e6a46da
c243168
53525fc
58193fc
973fd0a
ec5b9cc
8453d93
c0a348b
05182b5
9ccd074
5b5cb57
09ef059
61e3e55
04a0257
30b4da0
b33e3aa
beb9d25
a81c65b
18bd81e
1531831
e1d37b6
27cb619
349130a
3f80da9
7eded64
2fdd5d8
e638354
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,62 @@ | |||||||||||||||||
| --- | |||||||||||||||||
| name: Go | |||||||||||||||||
| on: | |||||||||||||||||
| pull_request: | |||||||||||||||||
| types: | |||||||||||||||||
| - unlabeled # if GitHub Actions stuck, add and remove "not ready" label to force rebuild | |||||||||||||||||
| - opened | |||||||||||||||||
| - reopened | |||||||||||||||||
| - synchronize | |||||||||||||||||
| push: | |||||||||||||||||
| branches: | |||||||||||||||||
| - ferretdb | |||||||||||||||||
| tags: | |||||||||||||||||
| - "*" | |||||||||||||||||
| schedule: | |||||||||||||||||
| - cron: "12 0 * * *" | |||||||||||||||||
|
|
|||||||||||||||||
| env: | |||||||||||||||||
| GOPATH: /home/runner/go | |||||||||||||||||
| GOCACHE: /home/runner/go/cache | |||||||||||||||||
| GOLANGCI_LINT_CACHE: /home/runner/go/cache/lint | |||||||||||||||||
| GOMODCACHE: /home/runner/go/mod | |||||||||||||||||
| GOPROXY: https://proxy.golang.org | |||||||||||||||||
| GOTOOLCHAIN: local | |||||||||||||||||
|
|
|||||||||||||||||
| jobs: | |||||||||||||||||
| test: | |||||||||||||||||
| name: Test | |||||||||||||||||
| # https://www.ubicloud.com/docs/about/pricing#github-actions | |||||||||||||||||
| # https://docs.github.com/en/billing/managing-billing-for-github-actions/about-billing-for-github-actions#per-minute-rates-for-larger-runners | |||||||||||||||||
| runs-on: ubicloud-standard-4 | |||||||||||||||||
|
|
|||||||||||||||||
| timeout-minutes: 15 | |||||||||||||||||
|
|
|||||||||||||||||
| # Do not run this job in parallel for any PR change or branch push. | |||||||||||||||||
| concurrency: | |||||||||||||||||
| 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') | |||||||||||||||||
|
|
|||||||||||||||||
| steps: | |||||||||||||||||
| # TODO https://github.com/FerretDB/github-actions/issues/211 | |||||||||||||||||
| - name: Checkout code | |||||||||||||||||
| uses: actions/checkout@v4 | |||||||||||||||||
|
|
|||||||||||||||||
| - name: Setup Go | |||||||||||||||||
| uses: FerretDB/github-actions/setup-go@main | |||||||||||||||||
|
|
|||||||||||||||||
| - name: Run tests | |||||||||||||||||
| run: | | |||||||||||||||||
| cd ferretdb_packaging | |||||||||||||||||
| go mod tidy | |||||||||||||||||
| go mod verify | |||||||||||||||||
| go test ./... | |||||||||||||||||
|
|
|||||||||||||||||
| - name: Check dirty | |||||||||||||||||
| if: always() | |||||||||||||||||
| run: | | |||||||||||||||||
| git status --untracked-files --ignored | |||||||||||||||||
| git status | |||||||||||||||||
| git diff --exit-code | |||||||||||||||||
|
Comment on lines
+28
to
+59
Check warningCode scanning / CodeQL Workflow does not contain permissions Medium
Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
Copilot AutofixAI 11 months ago To fix the problem, explicitly set the permissions:
contents: readNo additional methods, imports, or definitions are needed.
Suggested changeset
1
.github/workflows/ferretdb_go_tests.yml
Copilot is powered by AI and may make mistakes. Always verify output.
Refresh and try again.
|
|||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # FerretDB packaging | ||
| !*go.mod |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,210 @@ | ||
| // Copyright 2021 FerretDB Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| // Package main defines debian version number of DocumentDB for CI builds. | ||
| package main | ||
|
|
||
| import ( | ||
| "flag" | ||
| "fmt" | ||
| "os" | ||
| "regexp" | ||
| "slices" | ||
| "strings" | ||
|
|
||
| "github.com/sethvargo/go-githubactions" | ||
| ) | ||
|
|
||
| func main() { | ||
| controlFileF := flag.String("control-file", "../pg_documentdb/documentdb.control", "pg_documentdb/documentdb.control file path") | ||
|
|
||
| flag.Parse() | ||
|
|
||
| action := githubactions.New() | ||
|
|
||
| if *controlFileF == "" { | ||
| action.Fatalf("%s", "-control-file flag is empty.") | ||
| } | ||
|
|
||
| controlDefaultVersion, err := getControlDefaultVersion(*controlFileF) | ||
| if err != nil { | ||
| action.Fatalf("%s", err) | ||
| } | ||
|
|
||
| debugEnv(action) | ||
|
|
||
| packageVersion, err := definePackageVersion(controlDefaultVersion, action.Getenv) | ||
| if err != nil { | ||
| action.Fatalf("%s", err) | ||
| } | ||
|
|
||
| setResults(action, packageVersion) | ||
| } | ||
|
|
||
| // controlDefaultVer matches major, minor and "patch" from default_version field in control file, | ||
| // see pg_documentdb_core/documentdb_core.control. | ||
| var controlDefaultVer = regexp.MustCompile(`(?m)^default_version = '(?P<major>[0-9]+)\.(?P<minor>[0-9]+)-(?P<patch>[0-9]+)'$`) | ||
|
|
||
| // semVerTag is a https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string, | ||
| // but with a leading `v`. | ||
| var semVerTag = regexp.MustCompile(`^v(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$`) | ||
|
|
||
| // disallowedVer matches disallowed characters of Debian `upstream_version` when used without `debian_revision`. | ||
| // See https://www.debian.org/doc/debian-policy/ch-controlfields.html#version. | ||
| var disallowedVer = regexp.MustCompile(`[^A-Za-z0-9~.+]`) | ||
|
|
||
| // debugEnv logs all environment variables that start with `GITHUB_` or `INPUT_` | ||
| // in debug level. | ||
| func debugEnv(action *githubactions.Action) { | ||
| res := make([]string, 0, 30) | ||
|
|
||
| for _, l := range os.Environ() { | ||
| if strings.HasPrefix(l, "GITHUB_") || strings.HasPrefix(l, "INPUT_") { | ||
| res = append(res, l) | ||
| } | ||
| } | ||
|
|
||
| slices.Sort(res) | ||
|
|
||
| action.Debugf("Dumping environment variables:") | ||
|
|
||
| for _, l := range res { | ||
| action.Debugf("\t%s", l) | ||
| } | ||
| } | ||
|
|
||
| // getControlDefaultVersion returns the default_version field from the control file | ||
| // in SemVer format (0.100-0 -> 0.100.0). | ||
| func getControlDefaultVersion(f string) (string, error) { | ||
| b, err := os.ReadFile(f) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
|
|
||
| match := controlDefaultVer.FindSubmatch(b) | ||
| if match == nil || len(match) != controlDefaultVer.NumSubexp()+1 { | ||
| return "", fmt.Errorf("control file did not find default_version: %s", f) | ||
| } | ||
|
|
||
| major := match[controlDefaultVer.SubexpIndex("major")] | ||
| minor := match[controlDefaultVer.SubexpIndex("minor")] | ||
| patch := match[controlDefaultVer.SubexpIndex("patch")] | ||
|
|
||
| return fmt.Sprintf("%s.%s.%s", major, minor, patch), nil | ||
| } | ||
|
|
||
| // definePackageVersion returns valid Debian package version, | ||
| // based on `default_version` in the control file and environment variables set by GitHub Actions. | ||
| // | ||
| // See https://www.debian.org/doc/debian-policy/ch-controlfields.html#version. | ||
| // We use `upstream_version` only. | ||
| // For that reason, we can't use `-`, so we replace it with `~`. | ||
| func definePackageVersion(controlDefaultVersion string, getenv githubactions.GetenvFunc) (string, error) { | ||
| var packageVersion string | ||
| var err error | ||
|
|
||
| switch event := getenv("GITHUB_EVENT_NAME"); event { | ||
| case "pull_request", "pull_request_target": | ||
| branch := strings.ToLower(getenv("GITHUB_HEAD_REF")) | ||
| packageVersion = definePackageVersionForPR(controlDefaultVersion, branch) | ||
|
|
||
| case "push", "schedule", "workflow_run": | ||
| refName := strings.ToLower(getenv("GITHUB_REF_NAME")) | ||
|
|
||
| switch refType := strings.ToLower(getenv("GITHUB_REF_TYPE")); refType { | ||
| case "branch": | ||
| packageVersion, err = definePackageVersionForBranch(controlDefaultVersion, refName) | ||
|
|
||
| case "tag": | ||
| packageVersion, err = definePackagerVersionForTag(refName) | ||
|
|
||
| default: | ||
| err = fmt.Errorf("unhandled ref type %q for event %q", refType, event) | ||
| } | ||
|
|
||
| default: | ||
| err = fmt.Errorf("unhandled event type %q", event) | ||
| } | ||
|
|
||
| if err != nil { | ||
| return "", err | ||
| } | ||
|
|
||
| if packageVersion == "" { | ||
| return "", fmt.Errorf("both packageVersion and err are nil") | ||
| } | ||
|
|
||
| return packageVersion, nil | ||
| } | ||
|
|
||
| // definePackageVersionForPR returns valid Debian package version for PR. | ||
| // See [definePackageVersion]. | ||
| func definePackageVersionForPR(controlDefaultVersion, branch string) string { | ||
| // for branches like "dependabot/submodules/XXX" | ||
| parts := strings.Split(branch, "/") | ||
| branch = parts[len(parts)-1] | ||
| res := fmt.Sprintf("%s-pr-%s", controlDefaultVersion, branch) | ||
|
|
||
| return disallowedVer.ReplaceAllString(res, "~") | ||
| } | ||
|
|
||
| // definePackageVersionForBranch returns valid Debian package version for branch. | ||
| // See [definePackageVersion]. | ||
| func definePackageVersionForBranch(controlDefaultVersion, branch string) (string, error) { | ||
| switch branch { | ||
| case "ferretdb": | ||
| return fmt.Sprintf("%s~branch~%s", controlDefaultVersion, branch), nil | ||
| default: | ||
| return "", fmt.Errorf("unhandled branch %q", branch) | ||
| } | ||
| } | ||
|
|
||
| // definePackagerVersionForTag returns valid Debian package version for tag. | ||
| // See [definePackageVersion]. | ||
| func definePackagerVersionForTag(tag string) (string, error) { | ||
| match := semVerTag.FindStringSubmatch(tag) | ||
| if match == nil || len(match) != semVerTag.NumSubexp()+1 { | ||
| return "", fmt.Errorf("unexpected tag syntax %q", tag) | ||
| } | ||
|
|
||
| major := match[semVerTag.SubexpIndex("major")] | ||
| minor := match[semVerTag.SubexpIndex("minor")] | ||
| patch := match[semVerTag.SubexpIndex("patch")] | ||
| prerelease := match[semVerTag.SubexpIndex("prerelease")] | ||
| buildmetadata := match[semVerTag.SubexpIndex("buildmetadata")] | ||
|
|
||
| if prerelease == "" { | ||
| return "", fmt.Errorf("prerelease is empty") | ||
| } | ||
|
|
||
| if !strings.Contains(prerelease, "ferretdb") { | ||
| return "", fmt.Errorf("prerelease %q should include `ferretdb`", prerelease) | ||
| } | ||
|
|
||
| if buildmetadata != "" { | ||
| return "", fmt.Errorf("buildmetadata %q is present", buildmetadata) | ||
| } | ||
|
|
||
| res := fmt.Sprintf("%s.%s.%s-%s", major, minor, patch, prerelease) | ||
| return disallowedVer.ReplaceAllString(res, "~"), nil | ||
| } | ||
|
|
||
| // setResults sets action output parameters, summary, etc. | ||
| func setResults(action *githubactions.Action, res string) { | ||
| output := fmt.Sprintf("version: %s", res) | ||
|
|
||
| action.AddStepSummary(output) | ||
| action.Infof("%s", output) | ||
| action.SetOutput("version", res) | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.