Skip to content
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
48 changes: 48 additions & 0 deletions .github/workflows/goreleaser-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: GoReleaser Check

# Validates .goreleaser.yaml against a real snapshot build (cross-compile +
# archive generation, no publish) so config/toolchain regressions surface on
# the PR instead of after release-please has already cut a tag & GitHub
# Release. See release-please.yml's `publish` job, which runs the real
# `goreleaser release --clean` only after that release already exists.

on:
pull_request:
branches: [ '**' ]
paths:
- '.goreleaser.yaml'
- '.github/workflows/goreleaser-check.yml'
- '.github/workflows/release-please.yml'
- 'go.mod'
- 'go.sum'
- 'version.go'
workflow_dispatch:

jobs:
snapshot:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true

- name: Validate GoReleaser config
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: latest
args: check

- name: Snapshot build (validates cross-compilation & archives)
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: latest
args: release --snapshot --clean
59 changes: 59 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Release Please

on:
push:
branches:
- master
workflow_dispatch:

permissions:
contents: write
pull-requests: write

jobs:
release-please:
runs-on: ubuntu-latest
outputs:
releases_created: ${{ steps.release.outputs.releases_created }}
tag_name: ${{ steps.release.outputs.tag_name }}
steps:
- uses: actions/checkout@v4

- uses: googleapis/release-please-action@v5
id: release
with:
config-file: .release-please-config.json
manifest-file: .release-please-manifest.json
target-branch: master

# Build & publish binaries only when release-please actually cut a release
# (i.e. a release-please PR was just merged to master).
publish:
needs: release-please
if: ${{ needs.release-please.outputs.releases_created == 'true' }}
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ needs.release-please.outputs.tag_name }}
fetch-depth: 0

- name: Install Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: latest
# release-please already created the GitHub Release (notes, tag);
# GoReleaser just builds & uploads the binary archives to it.
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# IDE files
.idea/
*.iml

# goreleaser build output
/dist/
51 changes: 51 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
version: 2
project_name: gopy

before:
hooks:
- go mod tidy

builds:
- id: gopy
main: .
binary: gopy
env:
- CGO_ENABLED=0
goos: [linux, darwin, windows]
goarch: [amd64, arm64]
ldflags:
- -s -w
- -X main.GitCommit={{ .ShortCommit }}
- -X 'main.VersionDate={{ .CommitDate }} UTC'

archives:
- id: gopy
formats: [tar.gz]
format_overrides:
- goos: windows
formats: [zip]
name_template: >-
{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}

checksum:
name_template: "checksums.txt"

changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
- "^ci:"
- "^Merge pull request"

release:
github:
owner: go-python
name: gopy
# release-please already created the GitHub Release for this tag (with its
# own changelog-derived notes); keep those notes as-is and just attach
# the built archives/checksums to it.
mode: keep-existing
prerelease: auto
name_template: "{{ .Tag }}"
30 changes: 30 additions & 0 deletions .release-please-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"release-type": "go",
"include-v-in-tag": true,
"bootstrap-sha": "d09ff0f8254c8bd4a131157bf276c83330930cb5",
"packages": {
".": {
"release-type": "go",
"changelog-path": "CHANGELOG.md",
"extra-files": [
{
"path": "version.go",
"type": "generic"
}
]
}
},
"changelog-sections": [
{ "type": "feat", "section": "Features", "hidden": false },
{ "type": "fix", "section": "Bug Fixes", "hidden": false },
{ "type": "perf", "section": "Performance Improvements", "hidden": false },
{ "type": "revert", "section": "Reverts", "hidden": false },
{ "type": "docs", "section": "Documentation", "hidden": false },
{ "type": "style", "section": "Styles", "hidden": true },
{ "type": "chore", "section": "Miscellaneous Chores", "hidden": true },
{ "type": "refactor", "section": "Code Refactoring", "hidden": false },
{ "type": "test", "section": "Tests", "hidden": true },
{ "type": "build", "section": "Build System", "hidden": false },
{ "type": "ci", "section": "Continuous Integration", "hidden": true }
]
}
3 changes: 3 additions & 0 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
".": "0.4.10"
}
37 changes: 9 additions & 28 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ DIRS=`go list ./...`
PYTHON=python3
PIP=$(PYTHON) -m pip

GIT_COMMIT=`git rev-parse --short HEAD`
VERS_DATE=`date -u +%Y-%m-%d\ %H:%M`
LDFLAGS=-X 'main.GitCommit=$(GIT_COMMIT)' -X 'main.VersionDate=$(VERS_DATE) UTC'

all: build

build:
build:
@echo "GO111MODULE = $(value GO111MODULE)"
$(GOBUILD) -v $(DIRS)
$(GOBUILD) -v -ldflags "$(LDFLAGS)" $(DIRS)

test:
@echo "GO111MODULE = $(value GO111MODULE)"
Expand Down Expand Up @@ -52,30 +56,7 @@ prereq:
@echo " _PyInit__gi, referenced from:..."
@echo


# NOTE: MUST update version number here prior to running 'make release' and edit this file!
VERS=v0.4.10
PACKAGE=main
GIT_COMMIT=`git rev-parse --short HEAD`
VERS_DATE=`date -u +%Y-%m-%d\ %H:%M`
VERS_FILE=version.go

release:
/bin/rm -f $(VERS_FILE)
@echo "// WARNING: auto-generated by Makefile release target -- run 'make release' to update" > $(VERS_FILE)
@echo "" >> $(VERS_FILE)
@echo "package $(PACKAGE)" >> $(VERS_FILE)
@echo "" >> $(VERS_FILE)
@echo "const (" >> $(VERS_FILE)
@echo " Version = \"$(VERS)\"" >> $(VERS_FILE)
@echo " GitCommit = \"$(GIT_COMMIT)\" // the commit JUST BEFORE the release" >> $(VERS_FILE)
@echo " VersionDate = \"$(VERS_DATE)\" // UTC" >> $(VERS_FILE)
@echo ")" >> $(VERS_FILE)
@echo "" >> $(VERS_FILE)
goimports -w $(VERS_FILE)
/bin/cat $(VERS_FILE)
git commit -am "$(VERS) release"
git tag -a $(VERS) -m "$(VERS) release"
git push
git push origin --tags
# Releases are managed by release-please (.github/workflows/release-please.yml):
# merging its release PR to master bumps version.go, tags the commit, and
# publishes the GitHub Release. GoReleaser then builds & uploads binaries to it.

3 changes: 3 additions & 0 deletions bind/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ type BindCfg struct {
PkgPrefix string
// rename Go exported symbols to python PEP snake_case
RenameCase bool
// gopy version string embedded in this binary, stamped into generated
// file headers so output can be traced back to the release that produced it
Version string
}

// ErrorList is a list of errors
Expand Down
35 changes: 18 additions & 17 deletions bind/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ var WindowsOS = false

// for all preambles: 1 = name of package (outname), 2 = cmdstr

// 3 = libcfg, 4 = GoHandle, 5 = CGoHandle, 6 = all imports, 7 = mainstr, 8 = exe pre C, 9 = exe pre go
// 3 = libcfg, 4 = GoHandle, 5 = CGoHandle, 6 = all imports, 7 = mainstr, 8 = exe pre C, 9 = exe pre go, 10 = gopy version
const (
goPreamble = `/*
cgo stubs for package %[1]s.
File is generated by gopy. Do not edit.
File is generated by gopy version %[10]s. Do not edit.
%[2]s
*/

Expand Down Expand Up @@ -263,8 +263,9 @@ func GoPyMainRun() {

`

// 3 = gopy version
PyBuildPreamble = `# python build stubs for package %[1]s
# File is generated by gopy. Do not edit.
# File is generated by gopy version %[3]s. Do not edit.
# %[2]s

from pybindgen import retval, param, Function, Module
Expand Down Expand Up @@ -317,11 +318,11 @@ mod.add_function('_gopy_clear_go_tls', None, [])
// appended to imports in py wrap preamble as key for adding at end
importHereKeyString = "%%%%%%<<<<<<ADDIMPORTSHERE>>>>>>>%%%%%%%"

// 3 = specific package name, 4 = spec pkg path, 5 = doc, 6 = imports
// 3 = specific package name, 4 = spec pkg path, 5 = doc, 6 = imports, 8 = gopy version
PyWrapPreamble = `%[5]s
# python wrapper for package %[4]s within overall package %[1]s
# This is what you import to use the package.
# File is generated by gopy. Do not edit.
# File is generated by gopy version %[8]s. Do not edit.
# %[2]s

# the following is required to enable dlopen to open the _go.so file
Expand Down Expand Up @@ -379,11 +380,11 @@ except Exception:
`

// exe version of preamble -- doesn't need complex code to load _ module
// 3 = specific package name, 4 = spec pkg path, 5 = doc, 6 = imports
// 3 = specific package name, 4 = spec pkg path, 5 = doc, 6 = imports, 8 = gopy version
PyWrapExePreamble = `%[5]s
# python wrapper for package %[4]s within standalone executable package %[1]s
# This is what you import to use the package.
# File is generated by gopy. Do not edit.
# File is generated by gopy version %[8]s. Do not edit.
# %[2]s

import collections
Expand Down Expand Up @@ -431,9 +432,9 @@ def Init():
`

// 3 = gencmd, 4 = vm, 5 = libext 6 = extraGccArgs, 7 = CFLAGS, 8 = LDLFAGS,
// 9 = windows special declspec hack
// 9 = windows special declspec hack, 10 = gopy version
MakefileTemplate = `# Makefile for python interface for package %[1]s.
# File is generated by gopy. Do not edit.
# File is generated by gopy version %[10]s. Do not edit.
# %[2]s

GOCMD=go
Expand Down Expand Up @@ -470,9 +471,9 @@ build:

`

// exe version of template: 3 = gencmd, 4 = vm, 5 = libext
// exe version of template: 3 = gencmd, 4 = vm, 5 = libext, 8 = gopy version
MakefileExeTemplate = `# Makefile for python interface for standalone executable package %[1]s.
# File is generated by gopy. Do not edit.
# File is generated by gopy version %[8]s. Do not edit.
# %[2]s

GOCMD=go
Expand Down Expand Up @@ -721,12 +722,12 @@ func (g *pyGen) genGoPreamble() {
exeprego = goExePreambleGo
}
g.gofile.Printf(goPreamble, g.cfg.Name, g.cfg.Cmd, libcfg, GoHandle, CGoHandle,
pkgimport, g.cfg.Main, exeprec, exeprego)
pkgimport, g.cfg.Main, exeprec, exeprego, g.cfg.Version)
g.gofile.Printf("\n// --- generated code for package: %[1]s below: ---\n\n", g.cfg.Name)
}

func (g *pyGen) genPyBuildPreamble() {
g.pybuild.Printf(PyBuildPreamble, g.cfg.Name, g.cfg.Cmd)
g.pybuild.Printf(PyBuildPreamble, g.cfg.Name, g.cfg.Cmd, g.cfg.Version)
}

func (g *pyGen) genPyWrapPreamble() {
Expand Down Expand Up @@ -784,9 +785,9 @@ func (g *pyGen) genPyWrapPreamble() {
impstr += importHereKeyString

if g.mode == ModeExe {
g.pywrap.Printf(PyWrapExePreamble, g.cfg.Name, g.cfg.Cmd, n, pkgimport, pkgDoc, impgenstr, impstr)
g.pywrap.Printf(PyWrapExePreamble, g.cfg.Name, g.cfg.Cmd, n, pkgimport, pkgDoc, impgenstr, impstr, g.cfg.Version)
} else {
g.pywrap.Printf(PyWrapPreamble, g.cfg.Name, g.cfg.Cmd, n, pkgimport, pkgDoc, impgenstr, impstr)
g.pywrap.Printf(PyWrapPreamble, g.cfg.Name, g.cfg.Cmd, n, pkgimport, pkgDoc, impgenstr, impstr, g.cfg.Version)
}
}

Expand Down Expand Up @@ -816,14 +817,14 @@ func (g *pyGen) genMakefile() {
}

if g.mode == ModeExe {
g.makefile.Printf(MakefileExeTemplate, g.cfg.Name, g.cfg.Cmd, gencmd, g.cfg.VM, g.libext, pycfg.CFlags, pycfg.LdFlags)
g.makefile.Printf(MakefileExeTemplate, g.cfg.Name, g.cfg.Cmd, gencmd, g.cfg.VM, g.libext, pycfg.CFlags, pycfg.LdFlags, g.cfg.Version)
} else {
winhack := ""
if WindowsOS {
winhack = fmt.Sprintf(`# windows-only sed hack here to fix pybindgen declaration of PyInit
sed -i "s/ PyInit_/ __declspec(dllexport) PyInit_/g" %s.c`, g.cfg.Name)
}
g.makefile.Printf(MakefileTemplate, g.cfg.Name, g.cfg.Cmd, gencmd, g.cfg.VM, g.libext, g.extraGccArgs, pycfg.CFlags, pycfg.LdFlags, winhack)
g.makefile.Printf(MakefileTemplate, g.cfg.Name, g.cfg.Cmd, gencmd, g.cfg.VM, g.libext, g.extraGccArgs, pycfg.CFlags, pycfg.LdFlags, winhack, g.cfg.Version)
}
}

Expand Down
Loading
Loading