๐ŸŒ Detecting your locationโ€ฆ
๐Ÿ“ข Advertisement โ€” Configure AdSense in Appearance โ†’ Customize โ†’ AdSense Settings

GitHub Actions CI/CD-Leitfaden 2026: Automatisieren Sie Tests und Bereitstellung

โฑ๏ธ2 min read  ยท  434 words
GitHub Actions CI/CD Guide 2026: Automate Testing and Deployment

GitHub-Aktionenist die am weitesten verbreitete CI/CD-Plattform im Jahr 2026. Kostenlos fรผr รถffentliche Repos und 2.000 Minuten/Monat fรผr private Repos, automatisiert es Tests, Erstellung und Bereitstellung direkt aus Ihrem GitHub-Repository. Dieser Leitfaden deckt alles vom ersten Workflow bis zur Produktionsbereitstellung ab.

Kernkonzepte

  • Arbeitsablauf:YAML-Datei in.github/workflows/
  • Ereignis:Auslรถser (Push, PR, Zeitplan, manuell)
  • Beruf:Satz von Schritten, die auf einem Lรคufer
  • ausgefรผhrt werden Schritt:Einzelner Befehl oder Aktion
  • Lรคufer:VM, auf der Ihr Job ausgefรผhrt wird (Ubuntu, Windows, macOS)

Erster Workflow: Test auf Push

# .github/workflows/test.yml
name: Test

on:
  push:
    branches: [main, develop]
  pull_request:
    branches: [main]

jobs:
  test:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.12'

      - name: Install dependencies
        run: |
          pip install -r requirements.txt

      - name: Run tests
        run: pytest --cov=. --cov-report=xml

      - name: Upload coverage
        uses: codecov/codecov-action@v4

Matrix-Builds (Testen mehrerer Versionen)

jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ['3.11', '3.12', '3.13']

    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}
      - run: pip install -r requirements.txt && pytest

Bereitstellung in der Produktion am Tag

name: Deploy

on:
  push:
    tags: ['v*']

jobs:
  deploy:
    runs-on: ubuntu-latest
    environment: production

    steps:
      - uses: actions/checkout@v4

      - name: Build Docker image
        run: |
          docker build -t myapp:${{ github.ref_name }} .
          docker tag myapp:${{ github.ref_name }} registry.example.com/myapp:latest

      - name: Push to registry
        run: |
          echo ${{ secrets.REGISTRY_TOKEN }} | docker login registry.example.com -u ci --password-stdin
          docker push registry.example.com/myapp:latest

      - name: Deploy via SSH
        uses: appleboy/ssh-action@v1
        with:
          host: ${{ secrets.SERVER_HOST }}
          username: deploy
          key: ${{ secrets.SSH_PRIVATE_KEY }}
          script: |
            docker pull registry.example.com/myapp:latest
            docker compose up -d

Caching-Abhรคngigkeiten (schnellere Builds)

      - name: Cache pip
        uses: actions/cache@v4
        with:
          path: ~/.cache/pip
          key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}

      - name: Cache node_modules
        uses: actions/cache@v4
        with:
          path: node_modules
          key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}

Geheimnisse verwenden

Speichern Sie API-Schlรผssel in GitHub-Einstellungen > Geheimnisse und Variablen > Aktionen. Zugriff in Workflows mit${{ secrets.MY_KEY }}. Geheimnisse werden niemals in Protokollen gedruckt.

      - name: Send deploy notification
        run: |
          curl -X POST ${{ secrets.SLACK_WEBHOOK }} 
            -H 'Content-type: application/json' 
            --data '{"text": "Deployed ${{ github.ref_name }}"}'

Fazit

GitHub Actions macht eine separate CI/CD-Infrastruktur รผberflรผssig. Beginnen Sie mit einem einfachen Test-Workflow, fรผgen Sie Matrix-Builds hinzu und gehen Sie dann zur automatisierten Bereitstellung รผber, die durch Tags ausgelรถst wird. Caching verkรผrzt die Bauzeit um 50โ€“80 %.

โœ๏ธ Leave a Comment

Your email address will not be published. Required fields are marked *

๐ŸŒ Read in:๐Ÿ‡ฌ๐Ÿ‡ง English๐Ÿ‡ฉ๐Ÿ‡ช Deutsch๐Ÿ‡ง๐Ÿ‡ท Portuguรชs๐Ÿ‡ธ๐Ÿ‡ฆ ุงู„ุนุฑุจูŠุฉ๐Ÿ‡ฎ๐Ÿ‡ณ เคนเคฟเคจเฅเคฆเฅ€๐Ÿ‡ง๐Ÿ‡ฉ เฆฌเฆพเฆ‚เฆฒเฆพ