0
0
mirror of https://github.com/thegeeklab/github-releases-notifier.git synced 2024-06-02 17:49:40 +02:00

try to cross-compile binaries

This commit is contained in:
Robert Kaussow 2020-01-15 10:00:03 +01:00
parent 1b24acfe2e
commit 011b2f371c
4 changed files with 123 additions and 75 deletions

View File

@ -5,6 +5,7 @@ def main(ctx):
linux('amd64'), linux('amd64'),
linux('arm64'), linux('arm64'),
linux('arm'), linux('arm'),
binaries([]),
] ]
after = notification() after = notification()
@ -82,42 +83,23 @@ def linux(arch):
}, },
'steps': [ 'steps': [
{ {
'name': 'build-push', 'name': 'build',
'image': 'golang:1.12', 'image': 'golang:1.12',
'environment': { 'environment': {
'CGO_ENABLED': '0' 'CGO_ENABLED': '0',
'BUILD_VERSION': '${DRONE_TAG##v}'
}, },
'commands': [ 'commands': [
'go build -v -ldflags "-X main.version=${DRONE_COMMIT_SHA:0:8}" -a -tags netgo -o release/%s/github-releases-notifier' % arch '[ -z "${BUILD_VERSION}" ] && BUILD_VERSION=${DRONE_COMMIT_SHA:0:8}',
'go build -v -ldflags "-X main.Version=$BUILD_VERSION" -a -tags netgo -o release/%s/github-releases-notifier' % arch
], ],
'when': {
'event': {
'exclude': [
'tag'
]
}
}
},
{
'name': 'build-tag',
'image': 'golang:1.12',
'environment': {
'CGO_ENABLED': '0'
},
'commands': [
'go build -v -ldflags "-X main.version=${DRONE_TAG##v}" -a -tags netgo -o release/%s/github-releases-notifier' % arch
],
'when': {
'event': [
'tag'
]
}
}, },
{ {
'name': 'executable', 'name': 'executable',
'image': 'golang:1.12', 'image': 'golang:1.12',
'commands': [ 'commands': [
'./release/%s/github-releases-notifier --help' % arch './release/%s/github-releases-notifier --help' % arch,
'./release/%s/github-releases-notifier --version' % arch
] ]
}, },
{ {
@ -175,6 +157,54 @@ def linux(arch):
} }
} }
def binaries(arch):
return {
'kind': 'pipeline',
'type': 'docker',
'name': 'build-binaries',
'steps': [
{
'name': 'build',
'image': 'techknowlogick/xgo:latest',
'environment': {
'BUILD_VERSION': '${DRONE_TAG##v}'
},
'commands': [
'[ -z "${BUILD_VERSION}" ] && BUILD_VERSION=${DRONE_COMMIT_SHA:0:8}',
'mkdir -p release/',
"xgo -ldflags \"-X main.Version=$BUILD_VERSION\" -tags netgo -targets 'linux/amd64,linux/arm-6,linux/arm64' -out github-releases-notifier-$BUILD_VERSION .",
'cp /build/* release/',
'ls -lah release/'
]
},
{
'name': 'publish',
'image': 'plugins/github-release',
'settings': {
'overwrite': True,
'api_key': {
'from_secret': 'github_token'
},
'title': '${DRONE_TAG}',
'note': 'CHANGELOG.md',
},
'when': {
'ref': [
'refs/tags/**'
]
}
}
],
'depends_on': [],
'trigger': {
'ref': [
'refs/heads/master',
'refs/tags/**',
'refs/pull/**'
]
}
}
def notification(): def notification():
return [{ return [{
'kind': 'pipeline', 'kind': 'pipeline',

View File

@ -44,31 +44,20 @@ platform:
arch: amd64 arch: amd64
steps: steps:
- name: build-push - name: build
image: golang:1.12 image: golang:1.12
commands: commands:
- go build -v -ldflags "-X main.version=${DRONE_COMMIT_SHA:0:8}" -a -tags netgo -o release/amd64/github-releases-notifier - "[ -z \"${BUILD_VERSION}\" ] && BUILD_VERSION=${DRONE_COMMIT_SHA:0:8}"
- go build -v -ldflags "-X main.Version=$BUILD_VERSION" -a -tags netgo -o release/amd64/github-releases-notifier
environment: environment:
BUILD_VERSION: ${DRONE_TAG##v}
CGO_ENABLED: 0 CGO_ENABLED: 0
when:
event:
exclude:
- tag
- name: build-tag
image: golang:1.12
commands:
- go build -v -ldflags "-X main.version=${DRONE_TAG##v}" -a -tags netgo -o release/amd64/github-releases-notifier
environment:
CGO_ENABLED: 0
when:
event:
- tag
- name: executable - name: executable
image: golang:1.12 image: golang:1.12
commands: commands:
- ./release/amd64/github-releases-notifier --help - ./release/amd64/github-releases-notifier --help
- ./release/amd64/github-releases-notifier --version
- name: dryrun - name: dryrun
image: plugins/docker image: plugins/docker
@ -120,31 +109,20 @@ platform:
arch: arm64 arch: arm64
steps: steps:
- name: build-push - name: build
image: golang:1.12 image: golang:1.12
commands: commands:
- go build -v -ldflags "-X main.version=${DRONE_COMMIT_SHA:0:8}" -a -tags netgo -o release/arm64/github-releases-notifier - "[ -z \"${BUILD_VERSION}\" ] && BUILD_VERSION=${DRONE_COMMIT_SHA:0:8}"
- go build -v -ldflags "-X main.Version=$BUILD_VERSION" -a -tags netgo -o release/arm64/github-releases-notifier
environment: environment:
BUILD_VERSION: ${DRONE_TAG##v}
CGO_ENABLED: 0 CGO_ENABLED: 0
when:
event:
exclude:
- tag
- name: build-tag
image: golang:1.12
commands:
- go build -v -ldflags "-X main.version=${DRONE_TAG##v}" -a -tags netgo -o release/arm64/github-releases-notifier
environment:
CGO_ENABLED: 0
when:
event:
- tag
- name: executable - name: executable
image: golang:1.12 image: golang:1.12
commands: commands:
- ./release/arm64/github-releases-notifier --help - ./release/arm64/github-releases-notifier --help
- ./release/arm64/github-releases-notifier --version
- name: dryrun - name: dryrun
image: plugins/docker image: plugins/docker
@ -196,31 +174,20 @@ platform:
arch: arm arch: arm
steps: steps:
- name: build-push - name: build
image: golang:1.12 image: golang:1.12
commands: commands:
- go build -v -ldflags "-X main.version=${DRONE_COMMIT_SHA:0:8}" -a -tags netgo -o release/arm/github-releases-notifier - "[ -z \"${BUILD_VERSION}\" ] && BUILD_VERSION=${DRONE_COMMIT_SHA:0:8}"
- go build -v -ldflags "-X main.Version=$BUILD_VERSION" -a -tags netgo -o release/arm/github-releases-notifier
environment: environment:
BUILD_VERSION: ${DRONE_TAG##v}
CGO_ENABLED: 0 CGO_ENABLED: 0
when:
event:
exclude:
- tag
- name: build-tag
image: golang:1.12
commands:
- go build -v -ldflags "-X main.version=${DRONE_TAG##v}" -a -tags netgo -o release/arm/github-releases-notifier
environment:
CGO_ENABLED: 0
when:
event:
- tag
- name: executable - name: executable
image: golang:1.12 image: golang:1.12
commands: commands:
- ./release/arm/github-releases-notifier --help - ./release/arm/github-releases-notifier --help
- ./release/arm/github-releases-notifier --version
- name: dryrun - name: dryrun
image: plugins/docker image: plugins/docker
@ -262,6 +229,48 @@ trigger:
depends_on: depends_on:
- testing - testing
---
kind: pipeline
type: docker
name: build-binaries
platform:
os: linux
arch: amd64
steps:
- name: build
image: techknowlogick/xgo:latest
commands:
- "[ -z \"${BUILD_VERSION}\" ] && BUILD_VERSION=${DRONE_COMMIT_SHA:0:8}"
- mkdir -p release/
- xgo -ldflags "-X main.Version=$BUILD_VERSION" -tags netgo -targets 'linux/amd64,linux/arm-6,linux/arm64' -out github-releases-notifier-$BUILD_VERSION .
- cp /build/* release/
- ls -lah release/
environment:
BUILD_VERSION: ${DRONE_TAG##v}
- name: publish
image: plugins/github-release
settings:
api_key:
from_secret: github_token
note: CHANGELOG.md
overwrite: true
title: ${DRONE_TAG}
when:
ref:
- refs/tags/**
trigger:
ref:
- refs/heads/master
- refs/tags/**
- refs/pull/**
depends_on:
- testing
--- ---
kind: pipeline kind: pipeline
type: docker type: docker
@ -332,9 +341,10 @@ depends_on:
- build-container-amd64 - build-container-amd64
- build-container-arm64 - build-container-arm64
- build-container-arm - build-container-arm
- build-binaries
--- ---
kind: signature kind: signature
hmac: 48723ecce577b6addd70c457f07360a1986bbb43b56034619bf9843efc797a4a hmac: 4c60720bd47e885df1e36d84a68edb5e4fb4f9030113a52dda16b37a7da11f85
... ...

0
CHANGELOG.md Normal file
View File

View File

@ -14,6 +14,9 @@ import (
"golang.org/x/oauth2" "golang.org/x/oauth2"
) )
// Version of current build
var Version = "devel"
// Config of env and args // Config of env and args
type Config struct { type Config struct {
GithubToken string `arg:"env:GITHUB_TOKEN,required"` GithubToken string `arg:"env:GITHUB_TOKEN,required"`
@ -29,6 +32,11 @@ func (c Config) Token() *oauth2.Token {
return &oauth2.Token{AccessToken: c.GithubToken} return &oauth2.Token{AccessToken: c.GithubToken}
} }
// Version prints version string
func (Config) Version() string {
return "github-releases-notifier " + Version
}
func main() { func main() {
_ = godotenv.Load() _ = godotenv.Load()