github-actions-maven-release

授权协议 Readme
开发语言 Python
所属分类 应用工具、 IM/聊天/语音工具
软件类型 开源软件
地区 不详
投 递 者 郭业
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

github action maven release

The GitHub Action for Maven releases wraps the Maven CLI to enable Maven release.For example, you can use this action for auto-incrementing your project version and release your java artifacts.

This github action is bot friendly: You can configure the credentials of a bot user, which would be used during the incremental commit.The commits by the bot can also be signed, giving you the guaranty that only the bot can release in your repo. Additionally,this give you a clean git history by highlighting nicely which commits where resulting from your CI.

Supporting this github action

Support this github action by staring this project. Surprisingly, it seems to be the only way for the github market place to highlight popular github actions.

Sample repository

We created a sample repository that will show you an example of how this github action can be used for releasing a Java application:https://github.com/qcastel/github-actions-maven-release-sample

Features

Obviously, this github actions uses maven release plugin. Although, we did add on top a few features that you may like.

Maven release uses Git behind it, therefore there were a few features related in customising the git configuration:

  • Signing the commits (GPG) resulting from the maven release [GPG]
  • Authenticating to private repository using an SSH key [SSH]
  • Configuring the git username and email [Bot]
  • Configuring the jdk version [JDK]

You may want to configure a bit maven too. We added the following features:

  • Specify the maven project path. In other words, if your maven project is not at the root of your repo, you can configure a sub path. [Custom project path]
  • Configure a private maven repository [Private maven repo]
  • Configure a docker registry [Docker registry]
  • Setup custom maven arguments and/or options to be used when calling maven commands [Maven options]
  • Configure a custom M2 folder [Custom M2]
  • Print the timestamp for every maven logs. Handy for troubleshooting performance issues in your CI. [Log timestamp]

For the maven releases, we got also some dedicated functionalities:

  • Skip the maven perform [Skip perform]
  • Roll back the maven perform if it failed to perform the release
  • Increment the major or minor version (by default, it's the patch version that is increased) [Major Minor version]
  • customise the version format completly [Customize version]

Usage

Setup your pom.xml for maven release

Before you even begin setting up this github action, you would need to set up your pom.xml first to be ready for maven releases.We recommend you to refer to the maven release plugin documentation for more details: https://maven.apache.org/maven-release/maven-release-plugin/

Nevertheless, we will give you some essential setups

Configure the SCM

You got two choices here:

  • Using SSH URL (Recommended)
<scm>
        <connection>scm:git:${project.scm.url}</connection>
        <developerConnection>scm:git:${project.scm.url}</developerConnection>
        <url>git@github.com:idhub-io/idhub-api.git</url>
        <tag>HEAD</tag>
    </scm>
  • Using HTTPS URL
<scm>
        <connection>scm:git:${project.scm.url}</connection>
        <developerConnection>scm:git:${project.scm.url}</developerConnection>
		<url>https://github.com/YOUR_REPO.git</url>
		<tag>HEAD</tag>
	</scm>

In the case of SSH, it will use the ssh-private-key to authenticate with the upstream.In the case of HTTPS, maven releases will use the access-token in this github actions to authenticate with the upstream.

Note: SSH is more elegant and usually the easiest one to setup due to the large amount of documents online on this subject.

maven release plugin

Add the maven release plugin dependency to your project

<plugin>
        <artifactId>maven-release-plugin</artifactId>
        <version>XXX</version>
        <configuration>
            <scmCommentPrefix>[ci skip]</scmCommentPrefix>
        </configuration>
    </plugin>

Personally, I usually the prefix [ci skip] which allows me to skip more easily any commits generated by the bot from the CI.

Setup the maven release github actions

Choose your version of this github action

If it's your first time using a github action, I invite you having a quick read to the github official recommendations:https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/security-hardening-for-github-actions#using-third-party-actions

It's important you understand how the versioning work and the risk/compromise of using master/tags/commit hash

If you are adventurous and like to be always on top of this github action, you can use the reference master :

 - name: Release
      uses: qcastel/github-actions-maven-release@master
      with:

If you are more reserve, you can use a tag instead. You can find the list of the tags for this github action here:

https://github.com/qcastel/github-actions-maven-release/tags

To use a tag:

 - name: Release
      uses: qcastel/github-actions-maven-release@TAG_NAME
      with:

If you are concerned about the security of this github action, you can also move to a commit hash:

 - name: Release
      uses: qcastel/github-actions-maven-release@COMMIT_HASH
      with:

Basic setup

For a simple repo with not much protection and private dependency, you can do:

with:
        access-token: ${{ secrets.GITHUB_ACCESS_TOKEN }}

Setup with SSH

Although you may found better to use a SSH key instead. For this, generate an SSH key with the method of your choice, or use an existing one.Personally, I like generating an SSH inside a temporary docker image and configure it as a deploy key in my repository:

docker run -it qcastel/maven-release:latest  bash
ssh-keygen -b 2048 -t rsa -f /tmp/sshkey -q -N ""
export SSH_PRIVATE_KEY=$(base64 /tmp/sshkey)
export SSH_PUBLIC_KEY=$(cat /tmp/sshkey.pub)
echo -n "Copy the following SSH private key and add it to your repo secrets under the name 'SSH_PRIVATE_KEY':"
echo $SSH_PRIVATE_KEY
echo "Copy the encoded SSH public key and add it as one of your repo deploy keys with write access:"
echo $SSH_PUBLIC_KEY

exit

Copy SSH_PRIVATE_KEY and add it as a new secret.

Copy SSH_PUBLIC_KEY and add it as a new deployment key with write access.

Finally, setup the github action with:

with:
          ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}

If you want to set up a passphrase for your key:

with:
          ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
          ssh-passphrase: ${{ secrets.SSH_PASSPHRASE }}

log Timestamp

It can be quite difficult to troubleshoot any performance issue on your CI, due to the lack of timestamp from maven by default.An example of it particular handy, is when you private maven repository is having performance issue that is affecting your CI.

We added the timestamp by default, you don't need to do anything particular to enable this feature.

The logs should look like:

14:27:09,491 [INFO] Downloading from spring-snapshots: https://repo.spring.io/snapshot/io/projectreactor/reactor-bom/Dysprosium-SR13/reactor-bom-Dysprosium-SR13.pom

Maven options

Adding maven arguments

You can add some maven arguments, which is handy for skipping tests:

with:
            maven-args: "-Dmaven.javadoc.skip=true -DskipTests -DskipITs -Ddockerfile.skip -DdockerCompose.skip"

Adding maven options

You can add some maven options. At the difference of the maven arguments, those one are explicitly for the maven release plugin.See https://maven.apache.org/maven-release/maven-release-plugin/prepare-mojo.html.

with:
            maven-options: "-DbranchName=hotfix"

JDK version

The default JDK version is JDK 17. Although you may want to compile your project with a specific JDK version. You will need to specify the JAVA_HOME variable with the according value.If you need a specific jdk version that is not in the list, please raise an issue in this github action to request it.

JDK 8

env:
 JAVA_HOME: /usr/lib/jvm/java-1.8-openjdk/

JDK 11

env:
 JAVA_HOME: /usr/lib/jvm/java-11-openjdk/

JDK 14

env:
 JAVA_HOME: /usr/lib/jvm/java-14-openjdk/

JDK 15

env:
 JAVA_HOME: /usr/lib/jvm/java-15-openjdk/

JDK 16

env:
 JAVA_HOME: /usr/lib/jvm/java-16-openjdk/

JDK 17

env:
 JAVA_HOME: /usr/lib/jvm/java-17-openjdk/

Customise the bot name

You can simply customise the bot name as follows:

with:
            git-release-bot-name: "release-bot"
            git-release-bot-email: "release-bot@example.com"

Customise the default branch

You may not want to release from your master branch, which is currently the default branch setup by this github action. You can customise the branch name you want to release on, here release, as follows:

with:
            release-branch-name: "release"

Skipping perform

If for a reason, you need to skip the maven release perfom, you can disable it as follow:

with:
            skip-perform: true

Increase major or minor version

By default, maven release will increase the patch version. If you are interested to actually increment the major or minor version, you can usethe following options:

For major version increment

1.0.0-SNAPSHOT -> 2.0.0-SNAPSHOT

with:
            version-major: true

For minor version increment

1.0.0-SNAPSHOT -> 1.2.0-SNAPSHOT

with:
            version-minor: true

Customize version

development version

You may want to fully customize the development version number. This option will allow you to fully take control on the version number format.

For Example, you could decide to only have a 2 part version number like 0.2-SNAPSHOT.

with:
            maven-development-version-number: ${parsedVersion.majorVersion}.\${parsedVersion.nextMinorVersion}-SNAPSHOT

Release version

You may want to fully customize the release version number. This option will allow you to fully take control on the version number format.

For Example, you could decide to only have a trailing 0 for releases like 0.2.0.

with:
            maven-release-version-number: ${parsedVersion.majorVersion}.\${parsedVersion.minorVersion}.0

Customise the M2 folder path

It's quite common for setting up a caching of your dependencies, that you will be interested to customise the .m2 localisation folder.

with:
            m2-home-folder: '/your-custom-path/.m2'

Setup a GPG key

If you want to set up a GPG key, you can do it by injecting your key via the secrets:

Note: GITHUB_GPG_KEY needs to be base64 encoded.if you haven't setup a GPG key yet, see next section.

with:
        gpg-enabled: "true"
        gpg-key-id: ${{ secrets.GITHUB_GPG_KEY_ID }}
        gpg-key: ${{ secrets.GITHUB_GPG_KEY }}

In case you want to skip the GPG step, you can set gpg-enabled: "false" or if you prefer to have the same behaviour in your IDE, add this maven plugin in your pom.xml to skip GPG step in the release phase:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-gpg-plugin</artifactId>
    <version>1.6</version>
    <configuration>
        <skip>true</skip>
    </configuration>
</plugin>

Setup a private maven repository

If you got a private maven repo to set up in the settings.xml, you can do:Note: we recommend putting those values in your repo secrets.

with:
        maven-repo-server-id: your-maven-repo-id
        maven-repo-server-username: ${{ secrets.MVN_REPO_PRIVATE_REPO_USER }}
        maven-repo-server-password: ${{ secrets.MVN_REPO_PRIVATE_REPO_PASSWORD }}

Setup a docker registry

If you got a private maven repo to set up in the settings.xml, you can do:Note: we recommend putting those values in your repo secrets.

with:
        docker-registry-id: your-docker-registry-id
        docker-registry-username: ${{ secrets.DOCKER_REGISTRY_USERNAME }}
        docker-registry-password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }}

Note: For docker hub, this would look like:

with:
        docker-registry-id: registry.hub.docker.com
        docker-registry-username: ${{ secrets.DOCKER_HUB_USERNAME }}
        docker-registry-password: ${{ secrets.DOCKER_HUB_PASSWORD }}

Configure your maven project

You may also be in the case where you got more than one maven projects inside the repo. We added an option that will make the release job move to the according directly before running the release:

with:
        maven-project-folder: "sub-folder/"

Setup the bot gpg key

Setting up a gpg key for your bot is a good security feature. This way, you can enforce sign commits in your repo,even for your release bot.

Screenshot-2019-11-28-at-20-47-06.png

This github action needs the key ID and the key base64 encoded.

with:
            gpg-enabled: true
            gpg-key-id: ${{ secrets.GPG_KEY_ID }}
            gpg-key: ${{ secrets.GPG_KEY }}

If you want to set up a passphrase:

with:
            gpg-enabled: true
            gpg-key-id: ${{ secrets.GPG_KEY_ID }}
            gpg-key: ${{ secrets.GPG_KEY }}
            gpg-passphrase: ${{ secrets.GPG_PASSPHRASE }} 

Generate the key

f you like how we created a SSH key pair, here is the same idea using a docker image to generate a GPG key:

docker run -it qcastel/maven-release:latest  bash
cat >genkey-batch <<EOF
 %no-protection
 Key-Type: default
 Subkey-Type: default
 Name-Real: bot
 Name-Email: bot@idhub.io
 Expire-Date: 0
EOF
gpg --batch --gen-key genkey-batch

Note: Don't exit the docker container as we are not done yet.

Get the KID

You can get the key ID doing the following:

gpg --list-secret-keys --keyid-format LONG

sec   rsa2048/3EFC3104C0088B08 2019-11-28 [SC]
      CBFD9020DAC388A77C68385C3EFC3104C0088B08
uid                 [ultimate] bot-openbanking4-dev (it's the bot openbanking4.dev key) <bot@openbanking4.dev>
ssb   rsa2048/7D1523C9952204C1 2019-11-28 [E]

The key ID for my bot is 3EFC3104C0088B08. Add this value into your github secret for this repo, under GPG_KEY_IDPS: the key id is not really a secret but we found more elegant to store it there than in plain text in the github action yml

Get the GPG public and private key

Now we need the raw key and base64 encode

echo 'Public key to add in your bot github account:'
gpg --armor --export FFD651809B1889DF
echo 'Private key to add to the CI secrets under GITHUB_GPG_KEY:'
gpg --export-secret-keys --armor FFD651809B1889DF | base64

exit

Copy the public key and import it to the bot account as a GPG key.Copy the private key and add it in your github repo secrets under GPG_KEY.

License

The Dockerfile and associated scripts and documentation in this project are release under the MIT License.

  • 本篇文章主要是对我最近使用 Github Action 的一些总结,自己以前有一个需求,就是希望写完代码上传到 Github 之后自动发布 Release,为了方便以后下载以备不时只需,所以花了点时间研究了一下自动化测试和部署,发现还挺好用的,这里主要就说一下我的配置逻辑,关于 Github Action 相关的知识还需自行阅读 Github Action 文档 运行流程 监听 Master 分支

  • 将 jar 包发布到 Github 的 Maven 仓库 前置条件 我的前置条件:Github 学生认证附赠的 packet 我使用了 personal access token (PAT) 来认证 GitHub Packages / GitHub API 0. 获得 PAT 参考(很详细,一步一步来):https://docs.github.com/en/enterprise-server@3.

  • 1. Update pom.xml file with below <scm>   <connection>scm:git:ssh://<User ID>@<Server Address>:<Port>/<Project Name></connection>   <url>scm:git:ssh://<User ID>@<Server Address>:<Port>/<Project Name><

  • This is a quick-start guide to deploying Maven projects to a remote repository and then using the maven-release-plugin to publish them on GitHub. Deploying to a remote repository When you perform a mv

  • 一 Git 设置用户签名 git config --global user.name wcw git config --global user.email 111@qq.com 1.1 Git常用配置 初始化本地库 git init 查看本地库状态 git status 添加暂存区 将本地文件添加到暂存区 git add 文件/目录 移出暂存区 移除暂存区、但文件依然存在于工作目录 g

  • 1.主要功能:maven打jar包时带上 git commit相关信息 2.项目地址:ktoso/maven-git-commit-id-plugin 3.说明:maven构建项目,打成jar包部署时,包名是一般是这样 winstar-cbc-platform-api-1.0.0-SNAPSHOT.jar。        并不是每次提交更新代码都要修改版本号,这样就会出出现打成的jar包名字完全一

  • GitHub Actions 持续集成 - 2. 将工程打包并上传至 Release 本文地址:blog.lucien.ink/archives/493 0. 摘要 之前挖了一个坑,慢慢补上。 上篇文章介绍了如何自动生成 Release 的内容,本文章旨在介绍如何借助 GitHub Actions 在 Release 时自动上传打包好的工程。 1. 现成的轮子 使用此 Action 可以将特定的文

 相关资料
  • GitHub Actions 是 GitHub 推出的一款 CI/CD 工具。 我们可以在每个 job 的 step 中使用 Docker 执行构建步骤。 on: pushname: CIjobs: my-job: name: Build runs-on: ubuntu-latest steps: - uses: actions/checkout@master

  • 我有一个推送到GitHub的SpringBoot项目,其中我有一些半集成测试,其中我使用嵌入式mongo作为数据库。我的构建在本地是成功的,测试正在通过,但是在运行“MavenJava”GitHub操作时,它会失败,原因如下:

  • 有没有大佬来帮我看一看,是关于github actions的,我在实现一个推送代码到指定分支上时,会自动触发在远程目标服务器上面部署运行springboot项目,但是每一次运行到以下代码的时候: 它就会一直卡在这里。但是事实上,这一个项目是被正确运行了,监听端口也有信息,但是工作流中会报错: 我有一点不明白,部署成功之后,不就是应该断开ssh连接吗?有没有大佬解决一下? 因为这个地方报错,所以它工

  • 在我的单元测试中,我使用<code>aws sdk 一开始,我试图将值设置为<code>~/。aws/credentials使用github工作流中的run命令: 原来我的测试文件: 我试图用另一种方式在我的测试中获得证书,但也不起作用: 最后,我尝试创建一个自定义的Action(使用动作js库,如:@action/core、@action/io、@action/exec),以获取AWS env值

  • 我计划将我们的Travis CI构建迁移到使用Docker进行每次提交测试的GitHub Actions。 我是否可以在本地重复运行这些新的GitHub操作工作流?是否有一种在本地运行任何GitHub操作工作流的通用方法?