Harden CI and release artifacts

This commit is contained in:
2026-08-11 23:15:18 +09:00
parent ed2ba07ce1
commit a0750e4d5f
8 changed files with 107 additions and 39 deletions

View File

@@ -39,6 +39,12 @@ jobs:
- name: Run tests - name: Run tests
run: go test ./... run: go test ./...
- name: Run vet
run: go vet ./...
- name: Check reachable vulnerabilities
run: go run golang.org/x/vuln/cmd/govulncheck@v1.6.0 ./...
- name: Build - name: Build
run: go build ./cmd/dataxl run: go build ./cmd/dataxl

View File

@@ -30,6 +30,12 @@ jobs:
- name: Run tests - name: Run tests
run: go test ./... run: go test ./...
- name: Run vet
run: go vet ./...
- name: Check reachable vulnerabilities
run: go run golang.org/x/vuln/cmd/govulncheck@v1.6.0 ./...
- name: Build release archives - name: Build release archives
env: env:
RELEASE_TAG: ${{ inputs.tag }} RELEASE_TAG: ${{ inputs.tag }}

View File

@@ -18,7 +18,7 @@ TSVへ変換したり、Excelからコピーした表を再び構造化データ
## インストール ## インストール
Go 1.24以上が必要です。 Go 1.25以上が必要です。
```sh ```sh
go install git.rumginger.org/agent/dataxl/cmd/dataxl@latest go install git.rumginger.org/agent/dataxl/cmd/dataxl@latest
@@ -114,9 +114,13 @@ map/arrayを復元します。
列パスは `.` でmapのキー、`[n]` で0始まりの配列indexを表します。たとえば 列パスは `.` でmapのキー、`[n]` で0始まりの配列indexを表します。たとえば
`orders[0].items[1].sku` は、最初の注文に含まれる2番目の商品の `sku` です。 `orders[0].items[1].sku` は、最初の注文に含まれる2番目の商品の `sku` です。
同じ行に `user``user.name` のような競合する列がある場合、先に読み込まれた `.``[``]` を含むmapキーや空のmapキーはJSON文字列を使ったbracket記法で
値を保持し、後続列で型を上書きしません。曖昧な復元を避けるため、親要素と子要素を 表します。たとえば `{"build.target": {"x[y]": 1}}`
同時に列として置かないでください `["build.target"]["x[y]"]` という列名になります
同じ行に `user``user.name` のような競合する列がある場合や、同名ヘッダーが
複数ある場合はエラーにします。どちらかの値だけを採用して正常終了することは
ありません。
## セル値の型推定 ## セル値の型推定
@@ -129,7 +133,22 @@ CSV、TSV、XLSXから構造化形式へ戻す際は、セル文字列を次の
- それ以外は文字列 - それ以外は文字列
郵便番号や商品コードを想定し、`00123``-01` のようなゼロ埋め値は文字列のまま 郵便番号や商品コードを想定し、`00123``-01` のようなゼロ埋め値は文字列のまま
保持します。日付、時刻、`null` は自動推定しません。 保持します。セルの前後空白も文字列の一部として保持し、` 42 ` のような値を数値に
変換しません。日付、時刻、`null` は自動推定しません。
## データ欠落を防ぐ検証
- JSON入力はUTF-8として検証し、1つの値と後続空白だけを許可します。2つ目の値、
不正な後続データ、object内の重複キーは、値を置換・無視せずエラーにします。
- YAML streamに複数文書がある場合は、順序を保った配列としてすべて変換します。
- UTF-8 BOM付きCSV/TSVでは先頭のBOMをencoding markerとして除去します。
- CSV/TSVはUTF-8として検証し、ヘッダーより列数が多い行をエラーにします。
- 空ヘッダー列に値がある場合、重複ヘッダー、復元時に型が競合する列パスは
エラーにします。
- scalar fieldを1つも持たないrecordは表で表現できないため、空行へ変換して
record数を失う代わりにエラーにします。空のrecord listは空の表へ変換できます。
- `rows``records``items` を行配列として展開するのは、それがオブジェクト唯一の
キーである場合だけです。同階層のmetadataを破棄しません。
## CLIオプション ## CLIオプション
@@ -139,6 +158,7 @@ CSV、TSV、XLSXから構造化形式へ戻す際は、セル文字列を次の
- `-to`: 出力形式。`json`, `yaml`, `toml`, `csv`, `tsv`, `xlsx` - `-to`: 出力形式。`json`, `yaml`, `toml`, `csv`, `tsv`, `xlsx`
- `-sheet`: XLSXの読み書きに使うシート名。既定値は `Sheet1` - `-sheet`: XLSXの読み書きに使うシート名。既定値は `Sheet1`
- `-pretty`: JSONなどの構造化出力を整形するか。既定値は `true` - `-pretty`: JSONなどの構造化出力を整形するか。既定値は `true`
- `-version`: バージョンを表示して終了します。
## 現在の制約 ## 現在の制約
@@ -146,7 +166,9 @@ CSV、TSV、XLSXから構造化形式へ戻す際は、セル文字列を次の
- XLSXは指定した1シートのみ読み書きします。 - XLSXは指定した1シートのみ読み書きします。
- セル値の型推定は、空文字、真偽値、整数、小数、文字列の範囲です。 - セル値の型推定は、空文字、真偽値、整数、小数、文字列の範囲です。
- 空のmap/arrayは表側で `{}` / `[]` と表示されますが、逆変換時は文字列になります。 - 空のmap/arrayは表側で `{}` / `[]` と表示されますが、逆変換時は文字列になります。
- mapキーに `.``[``]` を含む場合のescape記法は未対応です。 - structured形式の `null` と表形式の空文字は同じ空セルになります。
- top-level scalarやscalar配列は表側で `value` 列を使うため、逆変換時は
`value` キーを持つレコードになります。
- 複雑なExcel書式や数式の保持は目的外です。 - 複雑なExcel書式や数式の保持は目的外です。
## 開発者向け情報 ## 開発者向け情報

View File

@@ -40,7 +40,8 @@ type table struct {
} }
``` ```
CSV/TSV/XLSXの読み込みでは、短い行を空文字で埋めて列数を揃えます。 CSV/TSV/XLSXの読み込みでは、短い行を空文字で埋めて列数を揃えます。ヘッダーより
長い行は、名前のない値を破棄しないようエラーにします。
XLSXの書き出しではヘッダーを太字にし、1行目を固定します。 XLSXの書き出しではヘッダーを太字にし、1行目を固定します。
## Flattening ## Flattening
@@ -49,6 +50,7 @@ structured -> table では、入れ子のmap/arrayを列パスへ展開します
- map: `user.name` - map: `user.name`
- array: `items[0].sku` - array: `items[0].sku`
- delimiterを含むmap key: `settings["build.target"]`
- top-level scalar: `value` - top-level scalar: `value`
列順は安定性を優先してソートしています。Excel上で列の位置が変わっても、 列順は安定性を優先してソートしています。Excel上で列の位置が変わっても、
@@ -84,20 +86,37 @@ items[0].sku
- 小数または指数表記: float64 - 小数または指数表記: float64
- その他: string - その他: string
ゼロ埋め整数は、IDやコードを壊さないためstringとして保持します。複数列が同じパスで ゼロ埋め整数と前後に空白があるセルは、IDや文字列を壊さないためstringとして
異なる中間型を要求する場合は、先に構築された値を後続列で上書きしません。 保持します。複数列が同じパスで異なる中間型を要求する場合はエラーにし、入力列を
黙って捨てません。
### Path grammar ### Path grammar
現在の列パスは次の要素を扱います。 現在の列パスは次の要素を扱います。
```text ```text
path = key, { ".", key | "[", index, "]" }; path = first-key, { map-child | quoted-key | array-index };
index = digit, { digit }; first-key = bare-key | quoted-key;
map-child = ".", bare-key;
quoted-key = "[", JSON-string, "]";
array-index = "[", digit, { digit }, "]";
``` ```
実例は `user.name``items[0].sku``orders[0].items[1].qty` です。 実例は `user.name``items[0].sku``orders[0].items[1].qty` です。map keyに
区切り文字を含むmap keyのescapeは未対応です。 `.``[``]` が含まれる場合や空文字の場合は、`["build.target"]``[""]`
ようなJSON quoted keyを使います。連続したarray indexも扱うため、
`matrix[0][1]` を復元できます。入力サイズに対して過大なmemory allocationを
起こさないよう、pathは最大256要素、array indexは最大10000です。
## Structured input integrity
- JSON inputはUTF-8として検証します。decoderは最初の値の後まで読み、空白以外の
後続データを拒否します。object keyもtoken単位で読み、重複を拒否します。
- YAML decoderはstream終端まで読み、複数文書を順序付きsliceとして保持します。
- `rows``records``items` wrapperはオブジェクト唯一のキーである場合だけ
table rowsとして展開します。
- recordが存在するのにscalar fieldが1つもないstructured valueは、表へ変換すると
record数を失うため拒否します。空のrecord listは空の表として扱います。
## TOML Output ## TOML Output
@@ -110,10 +129,11 @@ TOMLはトップレベル配列を直接表せないため、表からTOMLへ出
- `gopkg.in/yaml.v3`: YAML読み書き - `gopkg.in/yaml.v3`: YAML読み書き
- `github.com/BurntSushi/toml`: TOML読み書き - `github.com/BurntSushi/toml`: TOML読み書き
Go 1.24以上を前提にしています。 Go 1.25以上を前提にしています。
## Error handling ## Error handling
- 未対応形式、decode失敗、workbook/sheet操作失敗は呼び出し元へerrorを返します。 - 未対応形式、decode失敗、workbook/sheet操作失敗は呼び出し元へerrorを返します。
- path復元中の型競合は既存値を保護するため、その列の適用を中止します。 - CSV/TSVのinvalid UTF-8、headerより長い行、値を持つ空header列を拒否します。
- path復元中の重複header、構文エラー、型競合は変換全体をerrorにします。
- XLSXのstyle・pane設定も通常の変換errorとして扱い、不完全なworkbookを成功扱いしません。 - XLSXのstyle・pane設定も通常の変換errorとして扱い、不完全なworkbookを成功扱いしません。

View File

@@ -2,7 +2,7 @@
## Requirements ## Requirements
- Go 1.24 or later - Go 1.25 or later
## Setup ## Setup
@@ -53,9 +53,14 @@ The current tests cover:
- JSON -> XLSX -> JSON round trip - JSON -> XLSX -> JSON round trip
- structured -> structured conversion without CLI/file I/O - structured -> structured conversion without CLI/file I/O
- extension normalization and format inference - extension normalization and format inference
- ragged table row padding - short table row padding and wider-row rejection
- conservative cell type inference, including zero-padded identifiers - conservative cell type inference, including zero-padded identifiers
- conflicting unflatten paths - whitespace and UTF-8 BOM preservation rules
- invalid UTF-8, duplicate keys, and trailing-data rejection for JSON
- multi-document YAML streams and empty-record table boundaries
- wrapper arrays with sibling metadata
- duplicate, blank, malformed, and conflicting headers
- nested arrays and JSON-quoted path keys
When adding a new format or path rule, add tests around both directions where When adding a new format or path rule, add tests around both directions where
possible. possible.
@@ -67,14 +72,18 @@ Gitea Actions workflows live under `.gitea/workflows`.
- `ci.yml`: runs on pushes to `main`, pull requests, and manual dispatch. - `ci.yml`: runs on pushes to `main`, pull requests, and manual dispatch.
- `release.yml`: runs on `v*` tag pushes and manual dispatch with a `tag` input. - `release.yml`: runs on `v*` tag pushes and manual dispatch with a `tag` input.
The CI workflow checks formatting, runs tests, builds the CLI, and performs a The CI workflow checks formatting, runs tests and `go vet`, scans reachable
small YAML -> TSV -> JSON smoke test. vulnerabilities with `govulncheck`, builds the CLI, and performs a small
YAML -> TSV -> JSON smoke test.
The release workflow runs tests, cross-builds release archives for Linux, The release workflow runs tests, cross-builds release archives for Linux,
macOS, and Windows on amd64/arm64, writes `checksums.txt`, creates or reuses a macOS, and Windows on amd64/arm64, writes `checksums.txt`, creates or reuses a
Gitea Release, and uploads the generated assets. It uses the built-in Gitea Release, and uploads the generated assets. It uses the built-in
`${{ secrets.GITEA_TOKEN }}` provided by Gitea Actions. `${{ secrets.GITEA_TOKEN }}` provided by Gitea Actions.
Release binaries receive their tag through the `main.buildVersion` linker
variable. Verify an extracted native binary with `dataxl -version`.
## Release Notes ## Release Notes
Create a release by pushing a version tag: Create a release by pushing a version tag:

12
go.mod
View File

@@ -1,20 +1,20 @@
module git.rumginger.org/agent/dataxl module git.rumginger.org/agent/dataxl
go 1.24.0 go 1.25.0
require ( require (
github.com/BurntSushi/toml v1.6.0 github.com/BurntSushi/toml v1.6.0
github.com/xuri/excelize/v2 v2.10.1 github.com/xuri/excelize/v2 v2.11.0
gopkg.in/yaml.v3 v3.0.1 gopkg.in/yaml.v3 v3.0.1
) )
require ( require (
github.com/richardlehane/mscfb v1.0.6 // indirect github.com/richardlehane/mscfb v1.0.7 // indirect
github.com/richardlehane/msoleps v1.0.6 // indirect github.com/richardlehane/msoleps v1.0.6 // indirect
github.com/tiendc/go-deepcopy v1.7.2 // indirect github.com/tiendc/go-deepcopy v1.7.2 // indirect
github.com/xuri/efp v0.0.1 // indirect github.com/xuri/efp v0.0.1 // indirect
github.com/xuri/nfp v0.0.2-0.20250530014748-2ddeb826f9a9 // indirect github.com/xuri/nfp v0.0.2-0.20250530014748-2ddeb826f9a9 // indirect
golang.org/x/crypto v0.48.0 // indirect golang.org/x/crypto v0.53.0 // indirect
golang.org/x/net v0.50.0 // indirect golang.org/x/net v0.56.0 // indirect
golang.org/x/text v0.34.0 // indirect golang.org/x/text v0.39.0 // indirect
) )

24
go.sum
View File

@@ -4,8 +4,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/richardlehane/mscfb v1.0.6 h1:eN3bvvZCp00bs7Zf52bxNwAx5lJDBK1tCuH19qq5aC8= github.com/richardlehane/mscfb v1.0.7 h1:oeoiM0WE79vHwE8RpIYYvIAc8ajTH2mb6UZm55/+EB0=
github.com/richardlehane/mscfb v1.0.6/go.mod h1:pe0+IUIc0AHh0+teNzBlJCtSyZdFOGgV4ZK9bsoV+Jo= github.com/richardlehane/mscfb v1.0.7/go.mod h1:pe0+IUIc0AHh0+teNzBlJCtSyZdFOGgV4ZK9bsoV+Jo=
github.com/richardlehane/msoleps v1.0.6 h1:9BvkpjvD+iUBalUY4esMwv6uBkfOip/Lzvd93jvR9gg= github.com/richardlehane/msoleps v1.0.6 h1:9BvkpjvD+iUBalUY4esMwv6uBkfOip/Lzvd93jvR9gg=
github.com/richardlehane/msoleps v1.0.6/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg= github.com/richardlehane/msoleps v1.0.6/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
@@ -14,18 +14,18 @@ github.com/tiendc/go-deepcopy v1.7.2 h1:Ut2yYR7W9tWjTQitganoIue4UGxZwCcJy3orjrrI
github.com/tiendc/go-deepcopy v1.7.2/go.mod h1:4bKjNC2r7boYOkD2IOuZpYjmlDdzjbpTRyCx+goBCJQ= github.com/tiendc/go-deepcopy v1.7.2/go.mod h1:4bKjNC2r7boYOkD2IOuZpYjmlDdzjbpTRyCx+goBCJQ=
github.com/xuri/efp v0.0.1 h1:fws5Rv3myXyYni8uwj2qKjVaRP30PdjeYe2Y6FDsCL8= github.com/xuri/efp v0.0.1 h1:fws5Rv3myXyYni8uwj2qKjVaRP30PdjeYe2Y6FDsCL8=
github.com/xuri/efp v0.0.1/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI= github.com/xuri/efp v0.0.1/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI=
github.com/xuri/excelize/v2 v2.10.1 h1:V62UlqopMqha3kOpnlHy2CcRVw1V8E63jFoWUmMzxN0= github.com/xuri/excelize/v2 v2.11.0 h1:HxaEFl6sRN2+8J5a8HaKq+0M4FsjBGMnWWtjOCPSG88=
github.com/xuri/excelize/v2 v2.10.1/go.mod h1:iG5tARpgaEeIhTqt3/fgXCGoBRt4hNXgCp3tfXKoOIc= github.com/xuri/excelize/v2 v2.11.0/go.mod h1:jxFLbzaIwGQ5ufFNvYfUOHqXhfPaNmP14KWfmNz2Uak=
github.com/xuri/nfp v0.0.2-0.20250530014748-2ddeb826f9a9 h1:+C0TIdyyYmzadGaL/HBLbf3WdLgC29pgyhTjAT/0nuE= github.com/xuri/nfp v0.0.2-0.20250530014748-2ddeb826f9a9 h1:+C0TIdyyYmzadGaL/HBLbf3WdLgC29pgyhTjAT/0nuE=
github.com/xuri/nfp v0.0.2-0.20250530014748-2ddeb826f9a9/go.mod h1:WwHg+CVyzlv/TX9xqBFXEZAuxOPxn2k1GNHwG41IIUQ= github.com/xuri/nfp v0.0.2-0.20250530014748-2ddeb826f9a9/go.mod h1:WwHg+CVyzlv/TX9xqBFXEZAuxOPxn2k1GNHwG41IIUQ=
golang.org/x/crypto v0.48.0 h1:/VRzVqiRSggnhY7gNRxPauEQ5Drw9haKdM0jqfcCFts= golang.org/x/crypto v0.53.0 h1:QZ4Muo8THX6CizN2vPPd5fBGHyogrdK9fG4wLPFUsto=
golang.org/x/crypto v0.48.0/go.mod h1:r0kV5h3qnFPlQnBSrULhlsRfryS2pmewsg+XfMgkVos= golang.org/x/crypto v0.53.0/go.mod h1:DNLU434OwVakk9PzuwV8w62mAJpRJL3vsgcfp4Qnsio=
golang.org/x/image v0.25.0 h1:Y6uW6rH1y5y/LK1J8BPWZtr6yZ7hrsy6hFrXjgsc2fQ= golang.org/x/image v0.38.0 h1:5l+q+Y9JDC7mBOMjo4/aPhMDcxEptsX+Tt3GgRQRPuE=
golang.org/x/image v0.25.0/go.mod h1:tCAmOEGthTtkalusGp1g3xa2gke8J6c2N565dTyl9Rs= golang.org/x/image v0.38.0/go.mod h1:/3f6vaXC+6CEanU4KJxbcUZyEePbyKbaLoDOe4ehFYY=
golang.org/x/net v0.50.0 h1:ucWh9eiCGyDR3vtzso0WMQinm2Dnt8cFMuQa9K33J60= golang.org/x/net v0.56.0 h1:Rw8j/hFzGvJUZwNBXnAtf5sVDVt+65SK2C7IxCxZt5o=
golang.org/x/net v0.50.0/go.mod h1:UgoSli3F/pBgdJBHCTc+tp3gmrU4XswgGRgtnwWTfyM= golang.org/x/net v0.56.0/go.mod h1:D3Ku6r+V6JROoZK144D2XfMHFcMq/0zSfLelVTCFKec=
golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk= golang.org/x/text v0.39.0 h1:UbZz4pLOvn600D6Oh6GGEI6VAmndrEBLv8/6BEXzyus=
golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA= golang.org/x/text v0.39.0/go.mod h1:3UwRclnC2g0TU9x8PZiyfOajCd1zaUNHF9cvqcQZ+ZM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

View File

@@ -14,6 +14,10 @@ fi
if [ -z "$version" ]; then if [ -z "$version" ]; then
version="dev" version="dev"
fi fi
if [[ "$version" != "dev" && ! "$version" =~ ^v[0-9]+\.[0-9]+\.[0-9]+([.-][0-9A-Za-z.-]+)?$ ]]; then
echo "invalid release version: $version" >&2
exit 1
fi
rm -rf dist rm -rf dist
mkdir -p dist mkdir -p dist
@@ -40,7 +44,7 @@ for target in "${targets[@]}"; do
CGO_ENABLED=0 GOOS="$goos" GOARCH="$goarch" go build \ CGO_ENABLED=0 GOOS="$goos" GOARCH="$goarch" go build \
-trimpath \ -trimpath \
-ldflags="-s -w" \ -ldflags="-s -w -X main.buildVersion=$version" \
-o "$workdir/$binary" \ -o "$workdir/$binary" \
./cmd/dataxl ./cmd/dataxl
@@ -56,3 +60,4 @@ for target in "${targets[@]}"; do
done done
(cd dist && sha256sum dataxl_* > checksums.txt) (cd dist && sha256sum dataxl_* > checksums.txt)
(cd dist && sha256sum -c checksums.txt)