Skip to main content
Skip to content

Erstellen eines Beispielworkflows

In diesem Tutorial erfährst du, wie du einen einfachen Workflow erstellst, der durch ein Pushereignis ausgelöst wird.

Einführung

In dieser Anleitung erfahren Sie, wie Sie einen einfachen Workflow erstellen, der ausgelöst wird, wenn Code per Push an Ihr Repository übertragen wird.

Für die ersten Schritte mit vorkonfigurierten Workflows durchsuchen Sie die Liste der Vorlagen im Repository der Aktions-/Starter-Workflows. Weitere Informationen finden Sie unter Verwenden von Workflowvorlagen.

Wichtig

Weitere Informationen zu bewährten Methoden zum Sichern Ihrer Workflows und zur sicheren Verwendung von GitHub Actions Features finden Sie unter Referenz zur sicheren Verwendung.

Erstellen eines Beispielworkflows

GitHub Actions verwendet YAML-Syntax zum Definieren des Workflows. Die einzelnen Workflows werden in deinem Coderepository jeweils als separate YAML-Datei in einem Verzeichnis mit dem Namen .github/workflows gespeichert.

Du kannst in deinem Repository einen Beispielworkflow erstellen, der immer dann automatisch eine Reihe von Befehlen auslöst, wenn Code per Push übertragen wird. In diesem Workflow GitHub Actions checkt den pushed Code aus, installiert das Bats-Testframework und führt einen grundlegenden Befehl aus, um die Bats-Version auszugeben: . bats -v

  1. Erstelle in deinem Repository das Verzeichnis .github/workflows/, um die Workflowdateien zu speichern.

  2. Erstelle im Verzeichnis .github/workflows/ eine neue Datei mit dem Namen learn-github-actions.yml, und füge den folgenden Code hinzu:

    YAML
    name: learn-github-actions
    run-name: ${{ github.actor }} is learning GitHub Actions
    on: [push]
    jobs:
      check-bats-version:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v6
          - uses: actions/setup-node@v7
            with:
              node-version: '24'
          - run: npm install -g bats
          - run: bats -v
    
  3. Übernehmen Sie diese Änderungen und übertragen Sie diese in Ihr GitHub Repository.

Ihre neue GitHub Actions Workflowdatei ist jetzt in Ihrem Repository installiert und wird automatisch ausgeführt, wenn jemand eine Änderung an das Repository überträgt. Informationen zum Ausführungsverlauf eines Workflows findest du unter Anzeigen der Aktivität einer Workflowausführung.

Grundlegendes zu Workflowdateien

In diesem Abschnitt wird anhand der einzelnen Zeilen des Einführungsbeispiels erläutert, wie du mithilfe der YAML-Syntax eine Workflowdatei erstellst.

YAML
name: learn-github-actions

Optional - The name of the workflow as it will appear in the "Actions" tab of the GitHub repository. If this field is omitted, the name of the workflow file will be used instead.

run-name: ${{ github.actor }} is learning GitHub Actions

Optional - The name for workflow runs generated from the workflow, which will appear in the list of workflow runs on your repository's "Actions" tab. This example uses an expression with the github context to display the username of the actor that triggered the workflow run. For more information, see Workflow syntax for GitHub Actions.

on: [push]

Specifies the trigger for this workflow. This example uses the push event, so a workflow run is triggered every time someone pushes a change to the repository or merges a pull request. This is triggered by a push to every branch; for examples of syntax that runs only on pushes to specific branches, paths, or tags, see Workflow syntax for GitHub Actions.

jobs:

Groups together all the jobs that run in the learn-github-actions workflow.

  check-bats-version:

Defines a job named check-bats-version. The child keys will define properties of the job.

    runs-on: ubuntu-latest

Configures the job to run on the latest version of an Ubuntu Linux runner. This means that the job will execute on a fresh virtual machine hosted by GitHub. For syntax examples using other runners, see Workflow syntax for GitHub Actions

    steps:

Groups together all the steps that run in the check-bats-version job. Each item nested under this section is a separate action or shell script.

      - uses: actions/checkout@v6

The uses keyword specifies that this step will run the actions/checkout@v6 action. This is an action that checks out your repository onto the runner, allowing you to run scripts or other actions against your code (such as build and test tools). You should use the checkout action any time your workflow will use the repository's code.

      - uses: actions/setup-node@v7
        with:
          node-version: '24'

This step uses the actions/setup-node@v7 action to install the specified version of the Node.js. (This example uses version 24.) This puts both the node and npm commands in your PATH.

      - run: