Skip to content
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

Add extension validation #8

Merged
merged 6 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#
# Automatically tag a merge with master, or build a new image from the tag.
#
# Secrets required:
# * `GITHUB_TOKEN` - A GitHub token with access to the repository.
# * `AWS_ACCESS_KEY_ID` - An AWS access key with write access to the CDN bucket.
# * `AWS_SECRET_ACCESS_KEY` - The secret for the AWS access key
# * `NPM_TOKEN` - An NPM token with access to the package.
#

name: Release

on:
push:
branches:
- main
paths:
- "version.go"

jobs:
tag-build-publish:
name: Tag & Release
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: "0" # make sure we get all commits!

- name: Read current version
run: |
grep 'const VERSION' version.go | sed -e 's/const VERSION Version = "\(v[^"]*\)"/GOBL_VERSION=\1/' >> $GITHUB_ENV

- name: Bump version and push tag
id: bump
uses: anothrNick/[email protected]
env:
CUSTOM_TAG: ${{ env.GOBL_VERSION }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_BRANCHES: main

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: "go.mod"

# Ensure we have a wasm_exec.js for the current version of Go
- name: Copy Go WASM Exec
if: ${{ steps.bump.new_tag == steps.bump.tag }}
run: cp "$(go env GOROOT)/misc/wasm/wasm_exec.js" ./wasm/worker/src

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
# either 'goreleaser' (default) or 'goreleaser-pro'
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution
# GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}

# Following actions are to release a new version of gobl-worker to NPM
# using the new wasm version in the CDN.

- name: Install Node.js
uses: actions/setup-node@v3
if: ${{ steps.bump.new_tag == steps.bump.tag }}
with:
node-version: 16.x
cache: "npm"
cache-dependency-path: "./wasm/worker/package-lock.json"

- name: Run npm install
if: ${{ steps.bump.new_tag == steps.bump.tag }}
working-directory: ./wasm/worker
run: npm install

- name: Update gobl-worker version
if: ${{ steps.bump.new_tag == steps.bump.tag }}
working-directory: ./wasm/worker
run: npm version --no-git-tag-version ${{ steps.bump.outputs.new_tag }}

- name: Build gobl-worker
if: ${{ steps.bump.new_tag == steps.bump.tag }}
working-directory: ./wasm/worker
run: npm run build

- name: Publish gobl-worker to NPM registry
if: ${{ steps.bump.new_tag == steps.bump.tag }}
uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.NPM_TOKEN }}
package: ./wasm/worker/package.json
access: public
33 changes: 33 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Test Go
on: [push]
jobs:
test:
name: Test
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: "go.mod"
id: go

- name: Install Dependencies
env:
GOPROXY: https://proxy.golang.org,direct
run: go mod download

- name: Test
run: go test -race -coverprofile=coverage.out -covermode=atomic ./...

- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}

# Skipping WASM test, this can be done by CLI
#- name: Test WASM
# run: GOOS=js GOARCH=wasm go test ./... -exec=$(go env GOROOT)/misc/wasm/go_js_wasm_exec
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ go 1.22
toolchain go1.22.1

require (
github.com/invopop/gobl v0.205.1
github.com/invopop/gobl v0.207.0
github.com/invopop/validation v0.8.0
github.com/joho/godotenv v1.5.1
github.com/lestrrat-go/libxml2 v0.0.0-20240905100032-c934e3fcb9d3
github.com/nbio/xml v0.0.0-20241028124227-eac89c735a80
Expand All @@ -16,15 +17,14 @@ require (

require (
cloud.google.com/go v0.116.0 // indirect
github.com/Masterminds/semver/v3 v3.3.0 // indirect
github.com/Masterminds/semver/v3 v3.3.1 // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/invopop/jsonschema v0.12.0 // indirect
github.com/invopop/validation v0.8.0 // indirect
github.com/invopop/yaml v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/magefile/mage v1.15.0 // indirect
Expand All @@ -34,6 +34,6 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/square/go-jose/v3 v3.0.0-20200630053402-0a67ce9b0693 // indirect
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
golang.org/x/crypto v0.29.0 // indirect
golang.org/x/crypto v0.31.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cloud.google.com/go v0.116.0 h1:B3fRrSDkLRt5qSHWe40ERJvhvnQwdZiHu0bJOpldweE=
cloud.google.com/go v0.116.0/go.mod h1:cEPSRWPzZEswwdr9BxE6ChEn01dWlTaF05LiC2Xs70U=
github.com/Masterminds/semver/v3 v3.3.0 h1:B8LGeaivUe71a5qox1ICM/JLl0NqZSW5CHyL+hmvYS0=
github.com/Masterminds/semver/v3 v3.3.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
github.com/Masterminds/semver/v3 v3.3.1 h1:QtNSWtVZ3nBfk8mAOu/B6v7FMJ+NHTIgUPi7rj+4nv4=
github.com/Masterminds/semver/v3 v3.3.1/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so=
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=
Expand All @@ -20,8 +20,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/invopop/gobl v0.205.1 h1:khW63/Hu2lzU+IpRN2RF71cfUttCizL0HHAmeakWHyE=
github.com/invopop/gobl v0.205.1/go.mod h1:DmPohPel8b3ta4nDKnXRNzWQlB89cN74e0/WwPUEZUU=
github.com/invopop/gobl v0.207.0 h1:Gv6aUYKLdwuAw9HOhkk8eUztsYXPbPy6e/DBoBUDXmI=
github.com/invopop/gobl v0.207.0/go.mod h1:DmPohPel8b3ta4nDKnXRNzWQlB89cN74e0/WwPUEZUU=
github.com/invopop/jsonschema v0.12.0 h1:6ovsNSuvn9wEQVOyc72aycBMVQFKz7cPdMJn10CvzRI=
github.com/invopop/jsonschema v0.12.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0=
github.com/invopop/validation v0.8.0 h1:e5hXHGnONHImgJdonIpNbctg1hlWy1ncaHoVIQ0JWuw=
Expand Down Expand Up @@ -78,18 +78,18 @@ gitlab.com/flimzy/testy v0.14.0 h1:2nZV4Wa1OSJb3rOKHh0GJqvvhtE03zT+sKnPCI0owfQ=
gitlab.com/flimzy/testy v0.14.0/go.mod h1:m3aGuwdXc+N3QgnH+2Ar2zf1yg0UxNdIaXKvC5SlfMk=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ=
golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg=
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
Expand Down
8 changes: 4 additions & 4 deletions internal/ctog/charges.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func newCharge(ac *document.AllowanceCharge) (*bill.Charge, error) {
}
if ac.ReasonCode != "" {
c.Ext = tax.Extensions{
untdid.ExtKeyCharge: tax.ExtValue(ac.ReasonCode),
untdid.ExtKeyCharge: cbc.Code(ac.ReasonCode),
}
}
if ac.Base != "" {
Expand Down Expand Up @@ -107,7 +107,7 @@ func newDiscount(ac *document.AllowanceCharge) (*bill.Discount, error) {
}
if ac.ReasonCode != "" {
d.Ext = tax.Extensions{
untdid.ExtKeyAllowance: tax.ExtValue(ac.ReasonCode),
untdid.ExtKeyAllowance: cbc.Code(ac.ReasonCode),
}
}
if ac.Base != "" {
Expand Down Expand Up @@ -157,7 +157,7 @@ func getLineCharge(ac *document.AllowanceCharge) (*bill.LineCharge, error) {
}
if ac.ReasonCode != "" {
c.Ext = tax.Extensions{
untdid.ExtKeyCharge: tax.ExtValue(ac.ReasonCode),
untdid.ExtKeyCharge: cbc.Code(ac.ReasonCode),
}
}
if ac.Reason != "" {
Expand Down Expand Up @@ -186,7 +186,7 @@ func getLineDiscount(ac *document.AllowanceCharge) (*bill.LineDiscount, error) {
}
if ac.ReasonCode != "" {
d.Ext = tax.Extensions{
untdid.ExtKeyAllowance: tax.ExtValue(ac.ReasonCode),
untdid.ExtKeyAllowance: cbc.Code(ac.ReasonCode),
}
}
if ac.Reason != "" {
Expand Down
4 changes: 2 additions & 2 deletions internal/ctog/ctog.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (c *Converter) NewInvoice(doc *document.Invoice) error {
Customer: c.getParty(doc.Transaction.Agreement.Buyer),
Tax: &bill.Tax{
Ext: tax.Extensions{
untdid.ExtKeyDocumentType: tax.ExtValue(doc.ExchangedDocument.TypeCode),
untdid.ExtKeyDocumentType: cbc.Code(doc.ExchangedDocument.TypeCode),
},
},
}
Expand Down Expand Up @@ -86,7 +86,7 @@ func (c *Converter) NewInvoice(doc *document.Invoice) error {
Text: note.Content,
}
if note.SubjectCode != "" {
n.Code = note.SubjectCode
n.Code = cbc.Code(note.SubjectCode)
}
c.inv.Notes = append(c.inv.Notes, n)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/ctog/lines.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (c *Converter) prepareLines(tsct *document.Transaction) error {
l.Item.Identities = append(l.Item.Identities, &org.Identity{
// This label corresponds to a code from the ISO 6523 ICD List. Mapping is not yet supported
Ext: tax.Extensions{
iso.ExtKeySchemeID: tax.ExtValue(it.Product.GlobalID.SchemeID),
iso.ExtKeySchemeID: cbc.Code(it.Product.GlobalID.SchemeID),
},
Code: cbc.Code(it.Product.GlobalID.Value),
})
Expand Down
2 changes: 1 addition & 1 deletion internal/ctog/party.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (c *Converter) getParty(party *document.Party) *org.Party {
}
p.Identities = append(p.Identities, &org.Identity{
Ext: tax.Extensions{
iso.ExtKeySchemeID: tax.ExtValue(party.GlobalID.SchemeID),
iso.ExtKeySchemeID: cbc.Code(party.GlobalID.SchemeID),
},
Code: cbc.Code(party.GlobalID.Value),
})
Expand Down
3 changes: 2 additions & 1 deletion internal/ctog/payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/invopop/gobl.cii/document"
"github.com/invopop/gobl/bill"
"github.com/invopop/gobl/catalogues/untdid"
"github.com/invopop/gobl/cbc"
"github.com/invopop/gobl/num"
"github.com/invopop/gobl/org"
"github.com/invopop/gobl/pay"
Expand Down Expand Up @@ -100,7 +101,7 @@ func getMeans(stlm *document.Settlement) *pay.Instructions {
inst := &pay.Instructions{
Key: paymentMeansCode(pm.TypeCode),
Ext: tax.Extensions{
untdid.ExtKeyPaymentMeans: tax.ExtValue(pm.TypeCode),
untdid.ExtKeyPaymentMeans: cbc.Code(pm.TypeCode),
},
}

Expand Down
20 changes: 5 additions & 15 deletions internal/gtoc/charges.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ func newCharge(c *bill.Charge) *document.AllowanceCharge {
if c.Reason != "" {
ac.Reason = c.Reason
}
if c.Ext[untdid.ExtKeyCharge] != "" {
ac.ReasonCode = c.Ext[untdid.ExtKeyCharge].String()
}
ac.ReasonCode = c.Ext.Get(untdid.ExtKeyCharge).String()
if c.Percent != nil {
p := c.Percent.String()
ac.Percent = p
Expand All @@ -64,9 +62,7 @@ func newDiscount(d *bill.Discount) *document.AllowanceCharge {
if d.Reason != "" {
ac.Reason = d.Reason
}
if d.Ext[untdid.ExtKeyAllowance] != "" {
ac.ReasonCode = d.Ext[untdid.ExtKeyAllowance].String()
}
ac.ReasonCode = d.Ext.Get(untdid.ExtKeyAllowance).String()
if d.Percent != nil {
p := d.Percent.String()
ac.Percent = p
Expand All @@ -85,9 +81,7 @@ func makeLineCharge(c *bill.LineCharge) *document.AllowanceCharge {
if c.Reason != "" {
ac.Reason = c.Reason
}
if c.Ext[untdid.ExtKeyCharge] != "" {
ac.ReasonCode = c.Ext[untdid.ExtKeyCharge].String()
}
ac.ReasonCode = c.Ext.Get(untdid.ExtKeyCharge).String()
if c.Percent != nil {
p := c.Percent.String()
ac.Percent = p
Expand All @@ -103,9 +97,7 @@ func makeLineDiscount(d *bill.LineDiscount) *document.AllowanceCharge {
if d.Reason != "" {
ac.Reason = d.Reason
}
if d.Ext[untdid.ExtKeyAllowance] != "" {
ac.ReasonCode = d.Ext[untdid.ExtKeyAllowance].String()
}
ac.ReasonCode = d.Ext.Get(untdid.ExtKeyAllowance).String()
if d.Percent != nil {
p := d.Percent.String()
ac.Percent = p
Expand All @@ -118,9 +110,7 @@ func makeTaxCategory(tax *tax.Combo) *document.Tax {
if tax.Category != "" {
c.TypeCode = tax.Category.String()
}
if tax.Ext[untdid.ExtKeyTaxCategory] != "" {
c.CategoryCode = tax.Ext[untdid.ExtKeyTaxCategory].String()
}
c.CategoryCode = tax.Ext.Get(untdid.ExtKeyTaxCategory).String()
if tax.Percent != nil {
c.RateApplicablePercent = tax.Percent.StringWithoutSymbol()
}
Expand Down
Loading
Loading