GitHub软件包:用于GitHub组织的单个Maven存储库 [英] GitHub packages: Single Maven repository for GitHub organization

查看:105
本文介绍了GitHub软件包:用于GitHub组织的单个Maven存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用GitHub软件包在GitHub组织中存储多个存储库的Maven工件.

存储库/组织机密

接下来,在您的组织或从中发布软件包的每个存储库中定义一个秘密.

为其命名(即 DEPLOY_GITHUB_TOKEN ),并将其值设置为上一步中创建的个人访问令牌.

存储库机密在存储库设置>中定义.秘密.该组织有一个类似的部门.

GitHub动作

最后,确保您将个人访问令牌作为名为 GITHUB_TOKEN 的环境变量传递到部署步骤.

在下面的示例中,将其设置为上一步中定义的 DEPLOY_GITHUB_TOKEN 密码的值.

 名称:内部版本上:释放:类型:[创建]职位:建造:名称:Build&部署运行:ubuntu-latest脚步:-用途:actions/checkout @ v2-名称:设置JDK 1.8用途:actions/setup-java @ v1和:Java版本:1.8-名称:使用Maven构建运行:mvn --batch-mode --update-snapshots安装-名称:部署到GitHub运行:mvn --batch-mode -DskipTests -DuseGitHubPackages = true部署环境:GITHUB_TOKEN:$ {{secrets.DEPLOY_GITHUB_TOKEN}} 

由于我将专用的Maven配置文件用于GitHub软件包存储库分发管理,因此我也使用 -DuseGitHubPackages = true 激活了它.

Maven个人资料

在下面的配置文件示例中,我将分发管理配置为使用外部/共享存储库 vlingo/vlingo-平台,就像@Danny Varod的答案中建议的那样.

 <!-pom.xml-><项目><!-...-><个人资料><个人资料>< id> github</id><激活><属性>< name> useGitHubPackages</name>< value> true</value></property></激活>< distributionManagement><存储库>< id> github</id>< name> GitHub软件包</name>< url> https://maven.pkg.github.com/vlingo/vlingo-platform</url></存储库></distributionManagement></profile></profiles></project> 

交叉发布于: https://dev.to/jakub_zalas/how-to-publish-maven-packages-to-a-single-github-repository-3lkc

可以在vlingo存储库中找到一个工作示例: https://github.com/vlingo/vlingo-platform/packages

I would like to use GitHub packages to store Maven artifacts for several repositories in a GitHub organization. Currently, it appears that for each project, a separate (Maven) repository configuration entry is required to point to that (GitHub) repository's Maven repository:

<repository>
  <id>github</id>
  <name>GitHub OWNER Apache Maven Packages</name>
  <url>https://maven.pkg.github.com/OWNER/REPOSITORY</url>
</repository>

The corresponding configuration for the Maven project that would be published is:

<distributionManagement>
   <repository>
     <id>github</id>
     <name>GitHub OWNER Apache Maven Packages</name>
     <url>https://maven.pkg.github.com/OWNER/REPOSITORY</url>
   </repository>
</distributionManagement>

Is there a way to configure the packages to all go to a single REPOSITORY? Setting the REPOSITORY to either a different existing or non-existing (GitHub) repository in the organization fails the build, as does removing the /REPOSITORY entirely

解决方案

Personal Access Token

secrets.GITHUB_TOKEN is defined by default but it is only sufficient to deploy to the current repository.

To make it work across repositories you'll need to define a new Personal Access Token in:

Select write:packages for the scope and all the repo scopes should be automatically selected for you.

Repository / Organisation secrets

Next, define a secret in your organisation or each of the repositories you need to publish packages from.

Give it a name (i.e. DEPLOY_GITHUB_TOKEN) and set its value to the Personal Access Token created in the previous step.

Repository secrets are defined in repository Settings > Secrets. There's a similar section for the organisation.

GitHub Action

Finally, make sure you pass your Personal Access Token to the deployment step as an environment variable called GITHUB_TOKEN.

In the example below, it's set to the value of the DEPLOY_GITHUB_TOKEN secret defined in the previous step.

name: Build

on:
  release:
    types: [created]
jobs:
  build:
    name: Build & Deploy
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: Set up JDK 1.8
        uses: actions/setup-java@v1
        with:
          java-version: 1.8

      - name: Build with Maven
        run: mvn --batch-mode --update-snapshots install

      - name: Deploy to GitHub
        run: mvn --batch-mode -DskipTests -DuseGitHubPackages=true deploy
        env:
          GITHUB_TOKEN: ${{ secrets.DEPLOY_GITHUB_TOKEN }}

Since I used a dedicated Maven profile for the GitHub package repository distribution management, I also activated it with -DuseGitHubPackages=true.

Maven profile

In the profile example below, I configured distribution management to use the external/shared repository vlingo/vlingo-platform just like suggested in @Danny Varod's answer.

<!-- pom.xml -->
<project>
  <!-- ... -->

  <profiles>
    <profile>
      <id>github</id>
      <activation>
        <property>
          <name>useGitHubPackages</name>
          <value>true</value>
        </property>
      </activation>
      <distributionManagement>
        <repository>
          <id>github</id>
          <name>GitHub Packages</name>
          <url>https://maven.pkg.github.com/vlingo/vlingo-platform</url>
        </repository>
      </distributionManagement>
    </profile>
  </profiles>
</project>

Cross posted from: https://dev.to/jakub_zalas/how-to-publish-maven-packages-to-a-single-github-repository-3lkc

A working example can be found in vlingo repositories: https://github.com/vlingo/vlingo-platform/packages

这篇关于GitHub软件包:用于GitHub组织的单个Maven存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆