# Pipeline waarmee BlueGit zichzelf bouwt, publiceert en uitrolt. # Geen speciale behandeling: dezelfde jobs als elke andere repository. # Zet op de repository de geheimen DEPLOY_HOST, DEPLOY_USER, DEPLOY_PORT, # DEPLOY_PATH en DEPLOY_SSH_KEY. Markeer ze als beschermd, en bescherm de # branch master. Een regel voor main blijft staan, zodat een oude # branch nog kan uitrollen. Dan komen die geheimen alleen mee op een # beschermde branch. stages: [test, build, release, deploy] variables: CGO_ENABLED: "0" jobs: test: stage: test image: golang:1.22 script: - go test ./... build: stage: build image: golang:1.22 needs: [test] script: - go build -trimpath -ldflags="-s -w" -o bluegit ./cmd/bluegit artifacts: paths: [bluegit] expire_in: 14d release: stage: release image: curlimages/curl:8.11.0 needs: [build] rules: - if: $CI_COMMIT_BRANCH == "master" - if: $CI_COMMIT_BRANCH == "main" script: - >- curl -fsS -X POST "$CI_API_URL/repos/$CI_PROJECT_PATH/releases" -H "Authorization: Bearer $CI_JOB_TOKEN" -H "Content-Type: application/json" -d "{\"tag\":\"v${CI_PIPELINE_ID}\",\"commit\":\"${CI_COMMIT_SHA}\",\"name\":\"BlueGit ${CI_PIPELINE_ID}\",\"assets\":[{\"job\":\"build\",\"path\":\"bluegit\",\"name\":\"bluegit\"}]}" deploy: stage: deploy image: alpine:3.20 needs: [build, release] rules: - if: $CI_COMMIT_BRANCH == "master" - if: $CI_COMMIT_BRANCH == "main" script: - apk add --no-cache openssh-client - mkdir -p ~/.ssh && chmod 700 ~/.ssh - printf '%s\n' "$DEPLOY_SSH_KEY" > ~/.ssh/id_ed25519 - chmod 600 ~/.ssh/id_ed25519 - scp -i ~/.ssh/id_ed25519 -P "$DEPLOY_PORT" -o StrictHostKeyChecking=accept-new bluegit "$DEPLOY_USER@$DEPLOY_HOST:$DEPLOY_PATH.new" - 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" publish_aur: stage: deploy image: archlinux/archlinux:base-devel needs: [] allow_failure: true rules: - if: $CI_COMMIT_BRANCH == "master" - if: $CI_COMMIT_BRANCH == "main" script: - pacman -Syu --noconfirm - pacman -S --noconfirm --needed git openssh curl coreutils shadow util-linux - chmod +x scripts/aur-ssh-setup.sh scripts/publish-aur.sh - ./scripts/aur-ssh-setup.sh - ./scripts/publish-aur.sh