ci: add release pipeline

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

@ -2,22 +2,22 @@
// drone jsonnet --format --stream // drone jsonnet --format --stream
// local CreateRelease() = { local CreateRelease() = {
// name: 'create release', name: 'create release',
// image: 'plugins/gitea-release', image: 'plugins/gitea-release',
// settings: { settings: {
// api_key: { from_secret: 'GITEA_API_KEY' }, api_key: { from_secret: 'GITEA_API_KEY' },
// base_url: 'https://git.unlock-music.dev', base_url: 'https://git.unlock-music.dev',
// files: 'dist/*', files: 'dist/*',
// checksum: 'sha256', checksum: 'sha256',
// draft: true, draft: true,
// title: '${DRONE_TAG}', title: '${DRONE_TAG}',
// }, },
// }; };
local StepGoBuild(GOOS, GOARCH) = { local StepGoBuild(GOOS, GOARCH) = {
local filename = 'um-%s-%s.tar.gz' % [GOOS, GOARCH], local filepath = 'dist/um-%s-%s.tar.gz' % [GOOS, GOARCH],
name: 'go build', name: 'go build',
image: 'golang:1.19', image: 'golang:1.19',
@ -28,12 +28,13 @@ local StepGoBuild(GOOS, GOARCH) = {
commands: [ commands: [
'DIST_DIR=$(mktemp -d)', 'DIST_DIR=$(mktemp -d)',
'go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags --always)" -o $DIST_DIR ./cmd/um', '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, 'tar cz -f %s -C $DIST_DIR .' % filepath,
], ],
}; };
local StepUploadArtifact(GOOS, GOARCH) = { local StepUploadArtifact(GOOS, GOARCH) = {
local filename = 'um-%s-%s.tar.gz' % [GOOS, GOARCH], local filename = 'um-%s-%s.tar.gz' % [GOOS, GOARCH],
local filepath = 'dist/%s' % filename,
local pkgname = '${DRONE_REPO_NAME}-build', local pkgname = '${DRONE_REPO_NAME}-build',
name: 'upload artifact', name: 'upload artifact',
@ -44,9 +45,9 @@ local StepUploadArtifact(GOOS, GOARCH) = {
}, },
commands: [ commands: [
'curl --fail --include --user "um-release-bot:$GITEA_API_KEY" ' + 'curl --fail --include --user "um-release-bot:$GITEA_API_KEY" ' +
'--upload-file "%s" ' % filename + '--upload-file "%s" ' % filepath +
'"$DRONE_GITEA_SERVER/api/packages/${DRONE_REPO_NAMESPACE}/generic/%s/${DRONE_BUILD_NUMBER}/%s"' % [pkgname, filename], '"$DRONE_GITEA_SERVER/api/packages/${DRONE_REPO_NAMESPACE}/generic/%s/${DRONE_BUILD_NUMBER}/%s"' % [pkgname, filename],
'sha256sum %s' % filename, 'sha256sum %s' % filepath,
'echo $DRONE_GITEA_SERVER/${DRONE_REPO_NAMESPACE}/-/packages/generic/%s/${DRONE_BUILD_NUMBER}' % pkgname, 'echo $DRONE_GITEA_SERVER/${DRONE_REPO_NAMESPACE}/-/packages/generic/%s/${DRONE_BUILD_NUMBER}' % pkgname,
], ],
}; };
@ -80,8 +81,38 @@ local PipelineBuild(GOOS, GOARCH, RUN_TEST) = {
}, },
}; };
local PipelineRelease() = {
name: 'release',
kind: 'pipeline',
type: 'docker',
steps: [
{
name: 'fetch tags',
image: 'alpine/git',
commands: ['git fetch --tags'],
},
{
name: 'go test',
image: 'golang:1.19',
commands: ['go test -v ./...'],
},
StepGoBuild('linux', 'amd64'),
StepGoBuild('linux', 'arm64'),
StepGoBuild('linux', '386'),
StepGoBuild('windows', 'amd64'),
StepGoBuild('windows', '386'),
StepGoBuild('darwin', 'amd64'),
StepGoBuild('darwin', 'arm64'),
CreateRelease(),
],
trigger: {
event: ['tag'],
},
};
[ [
PipelineBuild('linux', 'amd64', true), PipelineBuild('linux', 'amd64', true),
PipelineBuild('windows', 'amd64', false), PipelineBuild('windows', 'amd64', false),
PipelineBuild('darwin', 'amd64', false), PipelineBuild('darwin', 'amd64', false),
PipelineRelease(),
] ]

@ -14,16 +14,16 @@ steps:
- DIST_DIR=$(mktemp -d) - DIST_DIR=$(mktemp -d)
- go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags - go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags
--always)" -o $DIST_DIR ./cmd/um --always)" -o $DIST_DIR ./cmd/um
- tar cz -f um-linux-amd64.tar.gz -C $DIST_DIR . - tar cz -f dist/um-linux-amd64.tar.gz -C $DIST_DIR .
environment: environment:
GOARCH: amd64 GOARCH: amd64
GOOS: linux GOOS: linux
image: golang:1.19 image: golang:1.19
name: go build name: go build
- commands: - commands:
- curl --fail --include --user "um-release-bot:$GITEA_API_KEY" --upload-file "um-linux-amd64.tar.gz" - curl --fail --include --user "um-release-bot:$GITEA_API_KEY" --upload-file "dist/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" "$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 - sha256sum dist/um-linux-amd64.tar.gz
- echo $DRONE_GITEA_SERVER/${DRONE_REPO_NAMESPACE}/-/packages/generic/${DRONE_REPO_NAME}-build/${DRONE_BUILD_NUMBER} - echo $DRONE_GITEA_SERVER/${DRONE_REPO_NAMESPACE}/-/packages/generic/${DRONE_REPO_NAME}-build/${DRONE_BUILD_NUMBER}
environment: environment:
DRONE_GITEA_SERVER: https://git.unlock-music.dev DRONE_GITEA_SERVER: https://git.unlock-music.dev
@ -48,16 +48,16 @@ steps:
- DIST_DIR=$(mktemp -d) - DIST_DIR=$(mktemp -d)
- go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags - go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags
--always)" -o $DIST_DIR ./cmd/um --always)" -o $DIST_DIR ./cmd/um
- tar cz -f um-windows-amd64.tar.gz -C $DIST_DIR . - tar cz -f dist/um-windows-amd64.tar.gz -C $DIST_DIR .
environment: environment:
GOARCH: amd64 GOARCH: amd64
GOOS: windows GOOS: windows
image: golang:1.19 image: golang:1.19
name: go build name: go build
- commands: - commands:
- curl --fail --include --user "um-release-bot:$GITEA_API_KEY" --upload-file "um-windows-amd64.tar.gz" - curl --fail --include --user "um-release-bot:$GITEA_API_KEY" --upload-file "dist/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" "$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 - sha256sum dist/um-windows-amd64.tar.gz
- echo $DRONE_GITEA_SERVER/${DRONE_REPO_NAMESPACE}/-/packages/generic/${DRONE_REPO_NAME}-build/${DRONE_BUILD_NUMBER} - echo $DRONE_GITEA_SERVER/${DRONE_REPO_NAMESPACE}/-/packages/generic/${DRONE_REPO_NAME}-build/${DRONE_BUILD_NUMBER}
environment: environment:
DRONE_GITEA_SERVER: https://git.unlock-music.dev DRONE_GITEA_SERVER: https://git.unlock-music.dev
@ -82,16 +82,16 @@ steps:
- DIST_DIR=$(mktemp -d) - DIST_DIR=$(mktemp -d)
- go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags - go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags
--always)" -o $DIST_DIR ./cmd/um --always)" -o $DIST_DIR ./cmd/um
- tar cz -f um-darwin-amd64.tar.gz -C $DIST_DIR . - tar cz -f dist/um-darwin-amd64.tar.gz -C $DIST_DIR .
environment: environment:
GOARCH: amd64 GOARCH: amd64
GOOS: darwin GOOS: darwin
image: golang:1.19 image: golang:1.19
name: go build name: go build
- commands: - commands:
- curl --fail --include --user "um-release-bot:$GITEA_API_KEY" --upload-file "um-darwin-amd64.tar.gz" - curl --fail --include --user "um-release-bot:$GITEA_API_KEY" --upload-file "dist/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" "$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 - sha256sum dist/um-darwin-amd64.tar.gz
- echo $DRONE_GITEA_SERVER/${DRONE_REPO_NAMESPACE}/-/packages/generic/${DRONE_REPO_NAME}-build/${DRONE_BUILD_NUMBER} - echo $DRONE_GITEA_SERVER/${DRONE_REPO_NAMESPACE}/-/packages/generic/${DRONE_REPO_NAME}-build/${DRONE_BUILD_NUMBER}
environment: environment:
DRONE_GITEA_SERVER: https://git.unlock-music.dev DRONE_GITEA_SERVER: https://git.unlock-music.dev
@ -104,3 +104,99 @@ trigger:
- push - push
- pull_request - pull_request
type: docker type: docker
---
kind: pipeline
name: release
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 dist/um-linux-amd64.tar.gz -C $DIST_DIR .
environment:
GOARCH: amd64
GOOS: linux
image: golang:1.19
name: go build
- 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 dist/um-linux-arm64.tar.gz -C $DIST_DIR .
environment:
GOARCH: arm64
GOOS: linux
image: golang:1.19
name: go build
- 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 dist/um-linux-386.tar.gz -C $DIST_DIR .
environment:
GOARCH: "386"
GOOS: linux
image: golang:1.19
name: go build
- 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 dist/um-windows-amd64.tar.gz -C $DIST_DIR .
environment:
GOARCH: amd64
GOOS: windows
image: golang:1.19
name: go build
- 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 dist/um-windows-386.tar.gz -C $DIST_DIR .
environment:
GOARCH: "386"
GOOS: windows
image: golang:1.19
name: go build
- 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 dist/um-darwin-amd64.tar.gz -C $DIST_DIR .
environment:
GOARCH: amd64
GOOS: darwin
image: golang:1.19
name: go build
- 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 dist/um-darwin-arm64.tar.gz -C $DIST_DIR .
environment:
GOARCH: arm64
GOOS: darwin
image: golang:1.19
name: go build
- image: plugins/gitea-release
name: create release
settings:
api_key:
from_secret: GITEA_API_KEY
base_url: https://git.unlock-music.dev
checksum: sha256
draft: true
files: dist/*
title: ${DRONE_TAG}
trigger:
event:
- tag
type: docker

Loading…
Cancel
Save