| 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 master. Een regel voor main blijft staan, zodat een oude |
| 6 | # branch nog kan uitrollen. Dan komen die geheimen alleen mee op een |
| 7 | # beschermde branch. |
| 8 | |
| 9 | stages: [test, build, release, deploy] |
| 10 | |
| 11 | variables: |
| 12 | CGO_ENABLED: "0" |
| 13 | |
| 14 | jobs: |
| 15 | test: |
| 16 | stage: test |
| 17 | image: golang:1.22 |
| 18 | script: |
| 19 | - go test ./... |
| 20 | |
| 21 | build: |
| 22 | stage: build |
| 23 | image: golang:1.22 |
| 24 | needs: [test] |
| 25 | script: |
| 26 | - go build -trimpath -ldflags="-s -w" -o bluegit ./cmd/bluegit |
| 27 | artifacts: |
| 28 | paths: [bluegit] |
| 29 | expire_in: 14d |
| 30 | |
| 31 | release: |
| 32 | stage: release |
| 33 | image: curlimages/curl:8.11.0 |
| 34 | needs: [build] |
| 35 | rules: |
| 36 | - if: $CI_COMMIT_BRANCH == "master" |
| 37 | - if: $CI_COMMIT_BRANCH == "main" |
| 38 | script: |
| 39 | - >- |
| 40 | curl -fsS -X POST "$CI_API_URL/repos/$CI_PROJECT_PATH/releases" |
| 41 | -H "Authorization: Bearer $CI_JOB_TOKEN" |
| 42 | -H "Content-Type: application/json" |
| 43 | -d "{\"tag\":\"v${CI_PIPELINE_ID}\",\"commit\":\"${CI_COMMIT_SHA}\",\"name\":\"BlueGit ${CI_PIPELINE_ID}\",\"assets\":[{\"job\":\"build\",\"path\":\"bluegit\",\"name\":\"bluegit\"}]}" |
| 44 | |
| 45 | deploy: |
| 46 | stage: deploy |
| 47 | image: alpine:3.20 |
| 48 | needs: [build, release] |
| 49 | rules: |
| 50 | - if: $CI_COMMIT_BRANCH == "master" |
| 51 | - if: $CI_COMMIT_BRANCH == "main" |
| 52 | script: |
| 53 | - apk add --no-cache openssh-client |
| 54 | - mkdir -p ~/.ssh && chmod 700 ~/.ssh |
| 55 | - printf '%s\n' "$DEPLOY_SSH_KEY" > ~/.ssh/id_ed25519 |
| 56 | - chmod 600 ~/.ssh/id_ed25519 |
| 57 | - scp -i ~/.ssh/id_ed25519 -P "$DEPLOY_PORT" -o StrictHostKeyChecking=accept-new bluegit "$DEPLOY_USER@$DEPLOY_HOST:$DEPLOY_PATH.new" |
| 58 | - 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" |
| 59 | |
| 60 | publish_aur: |
| 61 | stage: deploy |
| 62 | image: archlinux/archlinux:base-devel |
| 63 | needs: [] |
| 64 | allow_failure: true |
| 65 | rules: |
| 66 | - if: $CI_COMMIT_BRANCH == "master" |
| 67 | - if: $CI_COMMIT_BRANCH == "main" |
| 68 | script: |
| 69 | - pacman -Syu --noconfirm |
| 70 | - pacman -S --noconfirm --needed git openssh curl coreutils shadow util-linux |
| 71 | - chmod +x scripts/aur-ssh-setup.sh scripts/publish-aur.sh |
| 72 | - ./scripts/aur-ssh-setup.sh |
| 73 | - ./scripts/publish-aur.sh |