Skip to content

Commit 39ef0e8

Browse files
authored
Merge branch 'main' into add-test-for-tw
Signed-off-by: Debasish Biswas <debasishbsws.dev@gmail.com>
2 parents 6d04e24 + 97a0f0d commit 39ef0e8

File tree

83 files changed

+8840
-101
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+8840
-101
lines changed

.claude/settings.local.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"permissions": {
3+
"allow": [
4+
"Bash(go test:*)"
5+
]
6+
}
7+
}

.github/workflows/c-i.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ jobs:
2323
contents: read
2424
runs-on: ubuntu-24.04-${{matrix.arch}}
2525
steps:
26-
- uses: step-security/harden-runner@95d9a5deda9de15063e7595e9719c11c38c90ae2 # v2.13.2
26+
- uses: step-security/harden-runner@e3f713f2d8f53843e71c69a996d56f51aa9adfb9 # v2.14.1
2727
with:
2828
egress-policy: audit
29-
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
30-
- uses: chainguard-dev/actions/apt-faster@3e8a2a226fad9e1ecbf2d359b8a7697554a4ac6d # v1.5.10
31-
- uses: chainguard-dev/actions/setup-melange@3e8a2a226fad9e1ecbf2d359b8a7697554a4ac6d # v1.5.10
29+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
30+
- uses: chainguard-dev/actions/apt-faster@18e5e3427cf9d6bcfbefe60dca48e40292f000c5 # v1.5.13
31+
- uses: chainguard-dev/actions/setup-melange@18e5e3427cf9d6bcfbefe60dca48e40292f000c5 # v1.5.13
3232
- name: Set up Go
33-
uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0
33+
uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
3434
with:
3535
go-version-file: './go.work'
3636
cache-dependency-path: '**/*.sum'

README.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22
tw (pronounced tee-dub) is a centralized repository for testing and building
33
tools or helpers.
44

5-
## Release to Wolfi
6-
To release a version of tw to wolfi, run tools/release-to-wolfi.
5+
## Release to stereo
6+
To release a version of tw to stereo, run tools/release-to-stereo.
77

88
$ git tag vX.Y.Z
99
$ git push origin vX.Y.Z
10-
$ ./tools/release-to-wolfi vX.Y.Z \
11-
~/src/wolfi-os/ ~/src/enterprise-packages ~/src/extra-packages
10+
$ ./tools/release-to-stereo vX.Y.Z ~/git/cg/chainguard-dev/stereo/
1211

13-
This takes care of updating the `tw.yaml` file from `melange.yaml`
14-
for wolfi, and syncs the pipeline files for other dirs.
12+
This takes care of updating the `tw.yaml` file from `melange.yaml`,
13+
and syncs the pipeline files for other dirs.
1514

1615
That will do a commit and you just need to push and do a PR.
1716

@@ -27,6 +26,14 @@ make test-melange
2726
```
2827

2928
This validates that the tw tools package builds and functions correctly.
29+
In order to test a tw pipeline in a local stereo repository, you need the following steps:
30+
31+
* Build the tw tools package in this repository, `make build`.
32+
* If required, sync the pipeline yaml to stereo by hand.
33+
* If required, build the melange package with the new pipeline, in the stereo repository.
34+
* If required, test the melange package with the new pipeline, in the stereo repository.
35+
36+
Most likely, you need to tell the melange build in the stereo repository to use the tw index.
3037

3138
### 2. Project Tests (`test-projects`)
3239
Tests individual project subdirectories (e.g., `ldd-check`, `package-type-check`, `gosh`, etc.).
@@ -46,6 +53,11 @@ Tests the pipeline validators located in `pipelines/test/tw/` using test package
4653

4754
```bash
4855
make test-pipelines
56+
user@debian:~git/tw $ make build
57+
user@debian:~git/tw $ cp pipelines/test/tw/something.yaml ~/git/stereo/os/pipelines/test/tw/
58+
user@debian:~git/tw $ cd ~/git/stereo/enterprise-packages/
59+
user@debian:~git/stereo/os $ make debug/somepackage
60+
user@debian:~git/stereo/os $ MELANGE_DEBUG_TEST_OPTS="--ignore-signatures --repository-append ~/git/tw/packages" make test-debug/somepackage
4961
```
5062

5163
This runs a complete test suite that:

chelm/Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
PROJECT = chelm
2+
MELANGE_CONTEXTDIR ?= /tmp/melange-context/$(PROJECT)
3+
MELANGE_INSTALL_PATH = $(MELANGE_CONTEXTDIR)/usr/bin
4+
5+
.PHONY: build test clean melange-install
6+
7+
build:
8+
go build -o chelm .
9+
10+
test:
11+
go test -v ./...
12+
13+
clean:
14+
rm -f chelm
15+
16+
melange-install: build
17+
mkdir -p $(MELANGE_INSTALL_PATH)
18+
install -Dm755 chelm $(MELANGE_INSTALL_PATH)/chelm

chelm/chelm_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
"os"
7+
"testing"
8+
9+
"chainguard.dev/tw/chelm/cmd"
10+
"github.com/rogpeppe/go-internal/testscript"
11+
)
12+
13+
func TestMain(m *testing.M) {
14+
testscript.Main(m, map[string]func(){
15+
"chelm": chelmMain,
16+
})
17+
}
18+
19+
func chelmMain() {
20+
if err := cmd.Execute(); err != nil {
21+
fmt.Fprintln(os.Stderr, err)
22+
os.Exit(1)
23+
}
24+
}
25+
26+
var update = flag.Bool("update", false, "update testscript golden files")
27+
28+
func TestChelm(t *testing.T) {
29+
testscript.Run(t, testscript.Params{
30+
Dir: "testdata",
31+
UpdateScripts: *update,
32+
})
33+
}

chelm/cmd/generate.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package cmd
2+
3+
import (
4+
"encoding/json"
5+
"os"
6+
7+
"chainguard.dev/tw/chelm/internal/chelm"
8+
"github.com/spf13/cobra"
9+
)
10+
11+
var generateCmd = &cobra.Command{
12+
Use: "generate",
13+
Short: "Validate and format cg.json",
14+
Long: `Read Chainguard chart metadata as JSON from stdin, validate markers and test cases, and write formatted JSON.
15+
16+
Example:
17+
yq -n '.images.nginx.values.image = "${ref}"' -o=json | chelm generate -o cg.json`,
18+
RunE: func(cmd *cobra.Command, _ []string) error {
19+
output, _ := cmd.Flags().GetString("output")
20+
21+
w := cmd.OutOrStdout()
22+
if output != "-" {
23+
f, err := os.Create(output)
24+
if err != nil {
25+
return err
26+
}
27+
defer f.Close()
28+
w = f
29+
}
30+
31+
meta, err := chelm.Parse(cmd.InOrStdin())
32+
if err != nil {
33+
return err
34+
}
35+
enc := json.NewEncoder(w)
36+
enc.SetIndent("", " ")
37+
return enc.Encode(meta)
38+
},
39+
}
40+
41+
func init() {
42+
generateCmd.Flags().StringP("output", "o", "-", "Output file (- for stdout)")
43+
}

chelm/cmd/root.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package cmd
2+
3+
import "github.com/spf13/cobra"
4+
5+
var rootCmd = &cobra.Command{
6+
Use: "chelm",
7+
Short: "Validate Helm chart image mappings",
8+
Long: `chelm validates Helm chart image mappings for Chainguard packaging.
9+
10+
It complements melange pipelines, composing with helm template via stdin/stdout.`,
11+
SilenceUsage: true,
12+
SilenceErrors: true,
13+
}
14+
15+
func Execute() error {
16+
return rootCmd.Execute()
17+
}
18+
19+
func init() {
20+
rootCmd.AddCommand(generateCmd)
21+
rootCmd.AddCommand(testCmd)
22+
}

0 commit comments

Comments
 (0)