ci: init with go build

pull/44/head
Unlock Music Dev 2 years ago
parent 6c168ee536
commit 26b580a4b8
No known key found for this signature in database
GPG Key ID: 95202E10D3413A1D

@ -0,0 +1,87 @@
// generate .drone.yaml, run:
// drone jsonnet --format --stream
// local CreateRelease() = {
// name: 'create release',
// image: 'plugins/gitea-release',
// settings: {
// api_key: { from_secret: 'GITEA_API_KEY' },
// base_url: 'https://git.unlock-music.dev',
// files: 'dist/*',
// checksum: 'sha256',
// draft: true,
// title: '${DRONE_TAG}',
// },
// };
local StepGoBuild(GOOS, GOARCH) = {
local filename = 'um-%s-%s.tar.gz' % [GOOS, GOARCH],
name: 'go build',
image: 'golang:1.19',
environment: {
GOOS: GOOS,
GOARCH: GOARCH,
},
commands: [
'DIST_DIR=$(mktemp -d)',
'go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags --always)" -o $DIST_DIR ./cmd/um',
'tar cz -f %s -C $DIST_DIR .' % filename,
],
};
local StepUploadArtifact(GOOS, GOARCH) = {
local filename = 'um-%s-%s.tar.gz' % [GOOS, GOARCH],
local pkgname = '${DRONE_REPO_NAME}-build',
name: 'upload artifact',
image: 'golang:1.19', // reuse golang:1.19 for curl
environment: {
DRONE_GITEA_SERVER: 'https://git.unlock-music.dev',
GITEA_API_KEY: { from_secret: 'GITEA_API_KEY' },
},
commands: [
'curl --fail --include --user "um-release-bot:$GITEA_API_KEY" ' +
'--upload-file "%s" ' % filename +
'"$DRONE_GITEA_SERVER/api/packages/${DRONE_REPO_NAMESPACE}/generic/%s/${DRONE_BUILD_NUMBER}/%s"' % [pkgname, filename],
'sha256sum %s' % filename,
'echo $DRONE_GITEA_SERVER/${DRONE_REPO_NAMESPACE}/-/packages/generic/%s/${DRONE_BUILD_NUMBER}' % pkgname,
],
};
local PipelineBuild(GOOS, GOARCH, RUN_TEST) = {
name: 'build %s/%s' % [GOOS, GOARCH],
kind: 'pipeline',
type: 'docker',
steps: [
{
name: 'fetch tags',
image: 'alpine/git',
commands: ['git fetch --tags'],
},
] +
(
if RUN_TEST then [{
name: 'go test',
image: 'golang:1.19',
commands: ['go test -v ./...'],
}] else []
)
+
[
StepGoBuild(GOOS, GOARCH),
StepUploadArtifact(GOOS, GOARCH),
],
trigger: {
event: ['push', 'pull_request'],
},
};
[
PipelineBuild('linux', 'amd64', true),
PipelineBuild('windows', 'amd64', false),
PipelineBuild('darwin', 'amd64', false),
]

@ -0,0 +1,106 @@
---
kind: pipeline
name: build linux/amd64
steps:
- commands:
- git fetch --tags
image: alpine/git
name: fetch tags
- commands:
- go test -v ./...
image: golang:1.19
name: go test
- commands:
- DIST_DIR=$(mktemp -d)
- go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags
--always)" -o $DIST_DIR ./cmd/um
- tar cz -f um-linux-amd64.tar.gz -C $DIST_DIR .
environment:
GOARCH: amd64
GOOS: linux
image: golang:1.19
name: go build
- commands:
- curl --fail --include --user "um-release-bot:$GITEA_API_KEY" --upload-file "um-linux-amd64.tar.gz"
"$DRONE_GITEA_SERVER/api/packages/${DRONE_REPO_NAMESPACE}/generic/${DRONE_REPO_NAME}-build/${DRONE_BUILD_NUMBER}/um-linux-amd64.tar.gz"
- sha256sum um-linux-amd64.tar.gz
- echo $DRONE_GITEA_SERVER/${DRONE_REPO_NAMESPACE}/-/packages/generic/${DRONE_REPO_NAME}-build/${DRONE_BUILD_NUMBER}
environment:
DRONE_GITEA_SERVER: https://git.unlock-music.dev
GITEA_API_KEY:
from_secret: GITEA_API_KEY
image: golang:1.19
name: upload artifact
trigger:
event:
- push
- pull_request
type: docker
---
kind: pipeline
name: build windows/amd64
steps:
- commands:
- git fetch --tags
image: alpine/git
name: fetch tags
- commands:
- DIST_DIR=$(mktemp -d)
- go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags
--always)" -o $DIST_DIR ./cmd/um
- tar cz -f um-windows-amd64.tar.gz -C $DIST_DIR .
environment:
GOARCH: amd64
GOOS: windows
image: golang:1.19
name: go build
- commands:
- curl --fail --include --user "um-release-bot:$GITEA_API_KEY" --upload-file "um-windows-amd64.tar.gz"
"$DRONE_GITEA_SERVER/api/packages/${DRONE_REPO_NAMESPACE}/generic/${DRONE_REPO_NAME}-build/${DRONE_BUILD_NUMBER}/um-windows-amd64.tar.gz"
- sha256sum um-windows-amd64.tar.gz
- echo $DRONE_GITEA_SERVER/${DRONE_REPO_NAMESPACE}/-/packages/generic/${DRONE_REPO_NAME}-build/${DRONE_BUILD_NUMBER}
environment:
DRONE_GITEA_SERVER: https://git.unlock-music.dev
GITEA_API_KEY:
from_secret: GITEA_API_KEY
image: golang:1.19
name: upload artifact
trigger:
event:
- push
- pull_request
type: docker
---
kind: pipeline
name: build darwin/amd64
steps:
- commands:
- git fetch --tags
image: alpine/git
name: fetch tags
- commands:
- DIST_DIR=$(mktemp -d)
- go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags
--always)" -o $DIST_DIR ./cmd/um
- tar cz -f um-darwin-amd64.tar.gz -C $DIST_DIR .
environment:
GOARCH: amd64
GOOS: darwin
image: golang:1.19
name: go build
- commands:
- curl --fail --include --user "um-release-bot:$GITEA_API_KEY" --upload-file "um-darwin-amd64.tar.gz"
"$DRONE_GITEA_SERVER/api/packages/${DRONE_REPO_NAMESPACE}/generic/${DRONE_REPO_NAME}-build/${DRONE_BUILD_NUMBER}/um-darwin-amd64.tar.gz"
- sha256sum um-darwin-amd64.tar.gz
- echo $DRONE_GITEA_SERVER/${DRONE_REPO_NAMESPACE}/-/packages/generic/${DRONE_REPO_NAME}-build/${DRONE_BUILD_NUMBER}
environment:
DRONE_GITEA_SERVER: https://git.unlock-music.dev
GITEA_API_KEY:
from_secret: GITEA_API_KEY
image: golang:1.19
name: upload artifact
trigger:
event:
- push
- pull_request
type: docker
Loading…
Cancel
Save