Note: GitHub Packages is currently in beta for GitHub Enterprise Server 2.22. To join the beta for your GitHub Enterprise Server instance, use the sign-up form.
About GitHub Packages with GitHub Actions
GitHub Actions helfen Dir, Deine Workflows für die Softwareentwicklung am gleichen Ort zu automatisieren, an dem Du Code speicherst und an Pull Requests und Issues mitarbeitest. Du kannst einzelne Aufgaben schreiben, Aktionen genannt, und diese kombinieren um einen benutzerdefinierten Workflow zu erstellen. Mit GitHub Actions kannst Du End-to-End-Funktionen für die fortlaufende Integration (continuous integration CI) und die fortlaufende Bereitstellung (continuous deployment CD) direkt im Repository erstellen. For more information, see "About GitHub Actions."
You can extend the CI and CD capabilities of your repository by publishing or installing packages as part of your workflow.
Authenticating to package registries on GitHub
To authenticate to package registries on GitHub Enterprise Server, we recommend using the GITHUB_TOKEN
that GitHub Enterprise Server automatically creates for your repository when you enable GitHub Actions instead of a personal access token for authentication. It has read and write permissions for packages in the repository where the workflow runs. For forks, the GITHUB_TOKEN
is granted read access for the parent repository. Weitere Informationen findest Du unter „Authentifizierung mit dem GITHUB_TOKEN."
You can reference the GITHUB_TOKEN
in your workflow file using the {{secrets.GITHUB_TOKEN}}
context. Weitere Informationen findest Du unter „Authentifizierung mit dem GITHUB_TOKEN".
About permissions and package access for repository-owned packages
Note: Repository-owned packages include RubyGems, npm, Apache Maven, NuGet, Gradle, and Docker packages that use the package namespace docker.pkg.github.com
.
Wenn Sie GitHub Actions aktivieren, installiert GitHub eine GitHub App im Repository. The GITHUB_TOKEN
secret is a GitHub App installation access token. You can use the installation access token to authenticate on behalf of the GitHub App installed on your repository. Die Berechtigungen des Tokens sind auf das Repository beschränkt, in dem sich der Workflow befindet. For more information, see "Permissions for the GITHUB_TOKEN."
GitHub Packages allows you to push and pull packages through the GITHUB_TOKEN
available to a GitHub Actions workflow.
Publishing a package using an action
You can use GitHub Actions to automatically publish packages as part of your continuous integration (CI) flow. This approach to continuous deployment (CD) allows you to automate the creation of new package versions, if the code meets your quality standards. For example, you could create a workflow that runs CI tests every time a developer pushes code to a particular branch. If the tests pass, the workflow can publish a new package version to GitHub Packages.
Die Konfigurationsschritte variieren je nach Paketclient. Allgemeine Informationen zur Konfiguration eines Workflow für GitHub Actions findest Du auf „Konfigurieren eines Workflow."
The following example demonstrates how you can use GitHub Actions to build and test your app, and then automatically create a Docker image and publish it to GitHub Packages.
Create a new workflow file in your repository (such as .github/workflows/deploy-image.yml
), and add the following YAML:
name: Create and publish a Docker image
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# dokumentation.
on:
push:
branches: ['release']
jobs:
run-npm-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: npm install and build webpack
run: |
npm install
npm run build
- uses: actions/upload-artifact@main
with:
name: webpack artifacts
path: public/
run-npm-test:
runs-on: ubuntu-latest
needs: run-npm-build
strategy:
matrix:
os: [ubuntu-latest]
node-version: [12.x, 14.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- uses: actions/download-artifact@main
with:
name: webpack artifacts
path: public
- name: npm install, and test
run: |
npm install
npm test
env:
CI: true
build-and-push-image:
runs-on: ubuntu-latest
needs: run-npm-test
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Log in to GitHub Docker Registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: docker.pkg.github.com
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
push: true
tags: |
docker.pkg.github.com/${{ github.repository }}/octo-image:${{ github.sha }}
The relevant settings are explained in the following table. For full details about each element in a workflow, see "Workflow syntax for GitHub Actions."
|
Configures the Create and publish a Docker image workflow to run every time a change is pushed to the branch called release .
|
|
This job installs NPM and uses it to build the app. |
|
This job uses npm test to test the code. The needs: run-npm-build command makes this job dependent on the run-npm-build job.
|
|
This job publishes the package. The needs: run-npm-test command makes this job dependent on the run-npm-test job.
|
|
Creates a new step called Log in to GitHub Docker Registry , which logs in to the registry using the account and password that will publish the packages. Once published, the packages are owned by the account defined here.
|
|
Creates a new step called Build and push Docker image . This step runs as part of the build-and-push-image job.
|
|
Uses the Docker build-push-action action to build the image, based on your repository's Dockerfile . If the build succeeds, it pushes the image to GitHub Packages.
|
|
Sends the required parameters to the build-push-action action. These are defined in the subsequent lines.
|
|
Pushes this image to the registry if it is built successfully. |
|
Tags the image with the SHA of the commit that triggered the workflow. |
This new workflow will run automatically every time you push a change to a branch named release
in the repository. You can view the progress in the Actions tab.
A few minutes after the workflow has completed, the new package will visible in your repository. To find your available packages, see "Viewing a repository's packages."
Installing a package using an action
You can install packages as part of your CI flow using GitHub Actions. For example, you could configure a workflow so that anytime a developer pushes code to a pull request, the workflow resolves dependencies by downloading and installing packages hosted by GitHub Packages. Then, the workflow can run CI tests that require the dependencies.
Installing packages hosted by GitHub Packages through GitHub Actions requires minimal configuration or additional authentication when you use the GITHUB_TOKEN
.
Die Konfigurationsschritte variieren je nach Paketclient. Allgemeine Informationen zur Konfiguration eines Workflow für GitHub Actions findest Du auf „Konfigurieren eines Workflow."