Zum Inhalt springen
Trainingslager IT-Trainingslager

Anhang A: Spickzettel

Alles Wichtige aus Tag 0–15 auf wenigen Seiten. Die Zahl in Klammern ist der Tag, an dem du es geübt hast. Im Zweifel gelten gh <befehl> --help und die Dokumentation unter docs.github.com/actions.

gh für Workflows

Befehl Was er tut Tag
gh run list --limit 3 letzte Läufe mit ID 1
gh run list --workflow ci.yml nur ein Workflow 2
gh run watch --exit-status <ID> Lauf verfolgen, Exit-Code = Ergebnis 1
gh run view <ID> / -v Jobs / Jobs mit Steps 1, 2
gh run view <ID> --log / --log-failed ganzes Log / nur rote Steps 1
gh run view <ID> --json jobs --jq … maschinenlesbar 3
gh run rerun <ID> / gh run cancel <ID> neu starten / abbrechen 3, 5
gh run download <ID> -n <name> -D <dir> Artefakt laden 3
gh workflow run x.yml -f name=wert workflow_dispatch mit Eingabe 2
gh workflow list Workflows im Repository 2
gh cache list Caches 3
gh pr create --fill / checks --watch / merge --squash --delete-branch Pull-Request 2
gh release create/view/list/download Releases 7
gh secret set X --env produktion --body … Secret im Environment 10
gh ruleset list / check main Rulesets 4
gh attestation verify oci://… -R <du>/<repo> Attestation prüfen 8
gh api repos/{owner}/{repo}/… REST-API, {owner}/{repo} füllt gh 3

Aufbau eines Workflows

name: ci
on:
  push:
    branches: [main]
    tags: ['v*']
    paths-ignore: ['**.md']
  pull_request:
  workflow_dispatch:
    inputs:
      version: {required: true}
permissions:
  contents: read
concurrency:
  group: ci-${{ github.ref }}
  cancel-in-progress: true
env:
  IMAGE: ghcr.io/${{ github.repository_owner }}/notes-api
jobs:
  test:
    strategy:
      matrix:
        os: [ubuntu-24.04, ubuntu-24.04-arm]
    runs-on: ${{ matrix.os }}
    outputs:
      kurz: ${{ steps.sha.outputs.kurz }}
    steps:
      - uses: actions/checkout@<sha> # v7.0.1
        with:
          persist-credentials: false
      - id: sha
        run: echo "kurz=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
  weiter:
    needs: test
    if: github.event_name != 'pull_request'
    environment: produktion
    runs-on: [self-hosted, lab]
    permissions:
      contents: read
      id-token: write
    steps:
      - env:
          KURZ: ${{ needs.test.outputs.kurz }}
        run: echo "$KURZ"

Ausdrücke und Kontexte

Ausdruck Bedeutung Tag
${{ github.sha }}, github.ref_name, github.actor Commit, Branch/Tag, Auslöser 2
${{ inputs.x }} Eingabe von workflow_dispatch/workflow_call 2, 12
${{ steps.<id>.outputs.<n> }} Output eines Steps 2
${{ needs.<job>.outputs.<n> }} Output eines Jobs 2
${{ matrix.<n> }} Wert der Matrix 3
${{ secrets.X }}, github.token Secret, Token des Laufs 6, 10
if: success() / failure() / always() Step nach grün / rot / immer 2
if: inputs.laut Boolean – Vergleich im Ausdruck 15
contains(github.ref_name, '-') Text enthält 7

Fremder Text (Titel, Branch-Namen, Eingaben) nie direkt in run:, sondern über env: (9).

Dateien des Runners

Datei / Variable Zweck Tag
$GITHUB_OUTPUT name=wert → Step-Output 2
$GITHUB_STEP_SUMMARY Markdown auf der Seite des Laufs 2
$GITHUB_SHA, $GITHUB_REF_NAME, $GITHUB_REPOSITORY vom Runner gesetzt 2, 7
::error title=…::Text Annotation 13
shell: bash bash -e -o pipefail statt bash -e 15

Rechte des GITHUB_TOKEN

Recht Wofür Tag
contents: read Checkout – Vorgabe für jeden Workflow 9
contents: write Releases, Tags 7
packages: write Push nach GHCR 6
id-token: write OIDC-Token (Sigstore, Clouds) 8, 10
attestations: write Attestations ablegen 8
security-events: write SARIF nach Code scanning 8
issues: write Issues, Labels 15
actions: write andere Workflows starten 11

Actions im Buch

Action Zweck Tag
actions/checkout@v7 Code holen 1
actions/setup-go@v7 Go aus go.mod, mit Cache 1, 3
actions/upload-artifact@v7 / download-artifact@v8 Artefakte 3
golangci/golangci-lint-action@v9 Lint 4
docker/setup-buildx-action@v4 Buildx 6
docker/login-action@v4 Registry-Anmeldung 6
docker/metadata-action@v6 Tags und Labels aus Git 6, 7
docker/build-push-action@v7 bauen, pushen, cache-from/to: type=gha 6
aquasecurity/[email protected] Schwachstellen 8
anchore/[email protected] SBOM 8
actions/attest@v4 Provenance, mit sbom-path SBOM-Attestation 8
sigstore/[email protected] cosign 8
github/codeql-action/upload-sarif@v4 Funde nach Code scanning 8

Runner

Was Befehl Tag
Registrierungs-Token gh api -X POST repos/<du>/<repo>/actions/runners/registration-token 5
Anmelden ./config.sh --unattended --url … --token … --labels lab 5
Als Dienst sudo ./svc.sh install ubuntu / start / stop 5
Variablen für Jobs .env im Runner-Ordner, danach Neustart 11
ARC-Controller helm install arc … gha-runner-scale-set-controller 14
Scale Set helm install arc-notes -f arc-notes.yaml … gha-runner-scale-set 14
Runner-Pods kubectl -n arc-runners get pods / get ephemeralrunners 14

Sicherheit in fünf Zeilen

  1. Oben permissions: contents: read, mehr nur im Job (9).
  2. Actions mit SHA pinnen, Version als Kommentar, Dependabot hält sie aktuell (9, 10).
  3. Fremder Text nur über env: (9).
  4. checkout mit persist-credentials: false (9).
  5. Kein eigener Runner für Fork-Pull-Requests; Freigabe für alle Externen (5).

Fehlerbilder

Symptom Ursache Tag
Kein Lauf nach dem Push paths-ignore, falscher Branch, ungültiges YAML 2, 9, 15
does not have 'workflow_dispatch' trigger Datei ungültig oder nicht auf main 15
Resource not accessible by integration permissions: fehlt 15
Job bleibt queued kein Runner mit allen Labels / maxRunners erreicht 5, 14
Wert ist leer Tippfehler in Output/Secret, Secret im Environment 15
Step grün trotz Fehler Pipe ohne pipefail 15
Permission denied beim Start download-artifact ohne chmod +x 3
Conflict: an artifact with this name … gleicher Artefakt-Name in der Matrix 15
base branch policy prohibits the merge Ruleset, Check rot 4
permission denied von kubectl KUBECONFIG nicht gesetzt (k3s) 11