| 1 | # Upstream-volgbranch voor deze fork. |
| 2 | # |
| 3 | # Haalt branch `main` op van het oorspronkelijke project op GitHub en zet die |
| 4 | # geforceerd op branch `upstream-master` in deze repository. `upstream-master` |
| 5 | # is een pure volgbranch: lokale commits daarop worden overschreven. |
| 6 | # |
| 7 | # BlueGit kent (nog) geen geplande pipelines. Start deze pipeline handmatig |
| 8 | # (knop "Run pipeline" op master) of extern via |
| 9 | # POST /api/v1/projects/ict/rusty-teams/pipelines {"ref": "master"} |
| 10 | # Bij een gewone push of merge request draait er niets. |
| 11 | # |
| 12 | # Pushen gebeurt met het beschermde repositorygeheim UPSTREAM_PUSH_BOT_TOKEN |
| 13 | # (of anders UPSTREAM_PUSH_TOKEN): een BlueGit-access token met scope |
| 14 | # write_repository. Het job-token (CI_JOB_TOKEN) mag |
| 15 | # niet pushen en is alleen een terugval. Beschermde geheimen komen alleen mee |
| 16 | # op beschermde branches, zoals master. |
| 17 | # Zet nooit een token in deze (publieke) repository. `upstream-master` mag |
| 18 | # beschermd zijn: het pushtoken hoort bij een account met beheerrechten. |
| 19 | # |
| 20 | # De workflows in .github/ zijn voor GitHub Actions en worden door BlueGit |
| 21 | # genegeerd. |
| 22 | |
| 23 | workflow: |
| 24 | rules: |
| 25 | - if: $CI_PIPELINE_SOURCE == "push" |
| 26 | when: never |
| 27 | - if: $CI_PIPELINE_SOURCE == "merge_request_event" |
| 28 | when: never |
| 29 | - when: always |
| 30 | |
| 31 | variables: |
| 32 | UPSTREAM_URL: "https://github.com/danieldaeschle/rusty-teams.git" |
| 33 | UPSTREAM_BRANCH: "main" |
| 34 | TARGET_BRANCH: "upstream-master" |
| 35 | |
| 36 | sync-upstream: |
| 37 | stage: sync |
| 38 | image: bluegit/base |
| 39 | resource_group: upstream-sync |
| 40 | timeout: 15m |
| 41 | retry: |
| 42 | max: 1 |
| 43 | when: runner_system_failure |
| 44 | script: |
| 45 | - | |
| 46 | set -eu |
| 47 | rm -rf /tmp/upstream |
| 48 | git init -q --bare /tmp/upstream |
| 49 | cd /tmp/upstream |
| 50 | git fetch --no-tags "$UPSTREAM_URL" "+refs/heads/$UPSTREAM_BRANCH:refs/heads/$UPSTREAM_BRANCH" |
| 51 | echo "Upstream $UPSTREAM_BRANCH staat op $(git rev-parse "refs/heads/$UPSTREAM_BRANCH")" |
| 52 | # Voorkeur: UPSTREAM_PUSH_BOT_TOKEN (bottoken met scope write_repository), |
| 53 | # dan UPSTREAM_PUSH_TOKEN, dan het job-token (dat niet mag pushen). |
| 54 | RAW="${UPSTREAM_PUSH_BOT_TOKEN:-${UPSTREAM_PUSH_TOKEN:-}}" |
| 55 | if [ -n "$RAW" ]; then |
| 56 | # Spaties/regeleinden uit een geplakte waarde halen. |
| 57 | PUSH_TOKEN="$(printf '%s' "$RAW" | tr -d '[:space:]')" |
| 58 | echo "Pushtoken uit repositorygeheim (${#PUSH_TOKEN} tekens)." |
| 59 | else |
| 60 | PUSH_TOKEN="$CI_JOB_TOKEN" |
| 61 | echo "Geen pushgeheim (beschermd geheim? alleen op beschermde branches); job-token wordt gebruikt." |
| 62 | fi |
| 63 | unset RAW |
| 64 | export PUSH_TOKEN |
| 65 | # De runner zet via GIT_CONFIG_KEY_1/2 een URL-specifieke extraHeader met |
| 66 | # het job-token voor deze repository. Die wint van een gewone |
| 67 | # http.extraHeader, en het job-token mag niet pushen. Daarom alleen |
| 68 | # safe.directory (sleutel 0) houden en het pushtoken zelf meegeven. |
| 69 | GIT_CONFIG_COUNT=1 git -c http.extraHeader="Authorization: Bearer $PUSH_TOKEN" \ |
| 70 | push --force "$CI_PROJECT_URL.git" "refs/heads/$UPSTREAM_BRANCH:refs/heads/$TARGET_BRANCH" |
| 71 | echo "$TARGET_BRANCH staat nu op $(git rev-parse "refs/heads/$UPSTREAM_BRANCH")" |
| 72 | |
| 73 | stages: [sync] |