BlueGit

timfa bluegit

Files

bluegit / blue-ci-cd.yml

blue-ci-cd.yml

feat: eerste basis van BlueGit
timfa project_87923614_bot_3aff574f6f98414b945a8799374f9092 · pushed by timfa · 3 weeks ago
151aa352 History
blue-ci-cd.yml 2.0 KiB Download Raw
1# Pipeline waarmee BlueGit zichzelf bouwt, publiceert en uitrolt.
2# Geen speciale behandeling: dezelfde jobs als elke andere repository.
3# Zet op de repository de geheimen DEPLOY_HOST, DEPLOY_USER, DEPLOY_PORT,
4# DEPLOY_PATH en DEPLOY_SSH_KEY. Markeer ze als beschermd, en bescherm de
5# branch main (en master zolang die de standaard is). Dan komen die
6# geheimen alleen mee op een beschermde branch.
7
8stages: [test, build, release, deploy]
9
10variables:
11 CGO_ENABLED: "0"
12
13jobs:
14 test:
15 stage: test
16 image: golang:1.22
17 script:
18 - go test ./...
19
20 build:
21 stage: build
22 image: golang:1.22
23 needs: [test]
24 script:
25 - go build -trimpath -ldflags="-s -w" -o bluegit ./cmd/bluegit
26 artifacts:
27 paths: [bluegit]
28 expire_in: 14d
29
30 release:
31 stage: release
32 image: curlimages/curl:8.11.0
33 needs: [build]
34 rules:
35 - if: $CI_COMMIT_BRANCH == "master"
36 - if: $CI_COMMIT_BRANCH == "main"
37 script:
38 - >-
39 curl -fsS -X POST "$CI_API_URL/repos/$CI_PROJECT_PATH/releases"
40 -H "Authorization: Bearer $CI_JOB_TOKEN"
41 -H "Content-Type: application/json"
42 -d "{\"tag\":\"v${CI_PIPELINE_ID}\",\"commit\":\"${CI_COMMIT_SHA}\",\"name\":\"BlueGit ${CI_PIPELINE_ID}\",\"assets\":[{\"job\":\"build\",\"path\":\"bluegit\",\"name\":\"bluegit\"}]}"
43
44 deploy:
45 stage: deploy
46 image: alpine:3.20
47 needs: [build, release]
48 rules:
49 - if: $CI_COMMIT_BRANCH == "master"
50 - if: $CI_COMMIT_BRANCH == "main"
51 script:
52 - apk add --no-cache openssh-client
53 - mkdir -p ~/.ssh && chmod 700 ~/.ssh
54 - printf '%s\n' "$DEPLOY_SSH_KEY" > ~/.ssh/id_ed25519
55 - chmod 600 ~/.ssh/id_ed25519
56 - scp -i ~/.ssh/id_ed25519 -P "$DEPLOY_PORT" -o StrictHostKeyChecking=accept-new bluegit "$DEPLOY_USER@$DEPLOY_HOST:$DEPLOY_PATH.new"
57 - ssh -i ~/.ssh/id_ed25519 -p "$DEPLOY_PORT" -o StrictHostKeyChecking=accept-new "$DEPLOY_USER@$DEPLOY_HOST" "mv '$DEPLOY_PATH.new' '$DEPLOY_PATH' && chmod 755 '$DEPLOY_PATH' && systemctl restart bluegit"