Note: GitHub Actions was available for GitHub Enterprise Server 2.22 as a limited beta. The beta has ended. GitHub Actions is now generally available in GitHub Enterprise Server 3.0 or later. For more information, see the GitHub Enterprise Server 3.0 release notes.
- For more information about upgrading to GitHub Enterprise Server 3.0 or later, see "Upgrading GitHub Enterprise Server."
- For more information about configuring GitHub Actions after you upgrade, see the documentation for GitHub Enterprise Server 3.0.
Note: GitHub-hosted runners are not currently supported on GitHub Enterprise Server. You can see more information about planned future support on the GitHub public roadmap.
Einführung
In this guide, you'll learn about the basic components needed to create and use a packaged composite action. Diese Anleitung fokussiert jene Komponenten, welche zum Paketieren der Aktion benötigt werden. Daher hat der Aktions-Code nur minimale Funktionalität. The action prints "Hello World" and then "Goodbye", or if you provide a custom name, it prints "Hello [who-to-greet]" and then "Goodbye". The action also maps a random number to the random-number
output variable, and runs a script named goodbye.sh
.
Once you complete this project, you should understand how to build your own composite action and test it in a workflow.
Warning: When creating workflows and actions, you should always consider whether your code might execute untrusted input from possible attackers. Certain contexts should be treated as untrusted input, as an attacker could insert their own malicious content. For more information, see "Understanding the risk of script injections."
Vorrausetzungen
Before you begin, you'll create a GitHub Enterprise Server repository.
-
Create a new public repository on your GitHub Enterprise Server instance. You can choose any repository name, or use the following
hello-world-composite-action
example. Du kannst diese Dateien hinzufügen, nachdem Dein Projekt per Push an GitHub Enterprise Server übergeben wurde. Weitere Informationen finden Sie unter „Neues Repository erstellen“. -
Clone Dein Repository auf Deinen Computer. Weitere Informationen findest Du unter „Ein Repository clonen“.
-
Gehe in Deinem Terminal zum Verzeichnisse Deines neuen Repositorys.
cd hello-world-composite-action
-
In the
hello-world-composite-action
repository, create a new file calledgoodbye.sh
, and add the following example code:echo "Auf Wiedersehen"
-
From your terminal, make
goodbye.sh
executable.chmod +x goodbye.sh
-
Checken Sie von Ihrem Terminal aus Ihre
goodbye.sh
Datei ein.git add goodbye.sh git commit -m "Add goodbye script" git push
Eine Datei für die Metadaten der Aktion erstellen
-
In the
hello-world-composite-action
repository, create a new file calledaction.yml
and add the following example code. For more information about this syntax, see "runs
for a composite actions".action.yml
name: 'Hello World' description: 'Greet someone' inputs: who-to-greet: # id of input description: 'Who to greet' required: true default: 'World' outputs: random-number: description: "Random number" value: ${{ steps.random-number-generator.outputs.random-id }} runs: using: "composite" steps: - run: echo Hello ${{ inputs.who-to-greet }}. shell: bash - id: random-number-generator run: echo "::set-output name=random-id::$(echo $RANDOM)" shell: bash - run: ${{ github.action_path }}/goodbye.sh shell: bash
Diese Datei definiert die
Who-to-Greet-
Eingabe, ordnet die zuzufällig generierte Zahl derZufallszahl
Ausgabevariablen zu und führt dasgoodbye.sh
Skript aus. It also tells the runner how to execute the composite action.For more information about managing outputs, see "
outputs
for a composite action".Weitere Informationen zur Verwendung von
github.action_path
finden Sie unter "github context
". -
From your terminal, check in your
action.yml
file.git add action.yml git commit -m "Add action" git push
-
From your terminal, add a tag. This example uses a tag called
v1
. Weitere Informationen finden Sie unter „Informationen zu Aktionen“.git tag -a -m "Description of this release" v1 git push --follow-tags
Deine Aktion in einem Workflow testen
The following workflow code uses the completed hello world action that you made in "Creating an action metadata file".
Copy the workflow code into a .github/workflows/main.yml
file in another repository, but replace actions/hello-world-composite-action@v1
with the repository and tag you created. Darüber hinaus können Sie die Eingabe who-to-greet
durch Ihren Namen ersetzen.
.github/workflows/main.yml
on: [push]
jobs:
hello_world_job:
runs-on: ubuntu-latest
name: A job to say hello
steps:
- uses: actions/checkout@v2
- id: foo
uses: actions/hello-world-composite-action@v1
with:
who-to-greet: 'Mona the Octocat'
- run: echo random-number ${{ steps.foo.outputs.random-number }}
shell: bash
Klicke in Deinem Repository auf die Registerkarte Actions (Aktionen), und wähle die neueste Workflow-Ausführung aus. The output should include: "Hello Mona the Octocat", the result of the "Goodbye" script, and a random number.