Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: 重构 workflow #133

Merged
merged 2 commits into from
Sep 20, 2021
Merged

refactor: 重构 workflow #133

merged 2 commits into from
Sep 20, 2021

Conversation

kang8
Copy link
Contributor

@kang8 kang8 commented Aug 27, 2021

本次 PR 主要有三个改动:

  1. 解决 BUG

之前的流程有个问题:会对 PR 提交进行快照发布,但 PR 是开发者对现有仓库的改进或功能增强,并不能确保 PR 的质量。所以 PR 只是运行测试,以对 PR 内容质量的保证。

  1. 将 push 和 PR 分开

将 workflow 流程分为测试和发布快照,这样做的好处是当测试不通过时不会进行快照发布。并且在观感上来看,一眼就可以看出是测试出问题还是发布了问题。

image

上图,一眼就可以看出是发布快照出了问题。

  1. 更新版本快照名,从 maven 插件命令替换成了python 脚本

这是基于性能的考虑,在之前使用 maven 插件中,使用了两个 maven 插件:

- name: get current project version to set env.VERSION
run: echo "VERSION=`mvn help:evaluate -Dexpression=project.version -q -DforceStdout`" >> $GITHUB_ENV
- name: set snapshot version
if: ${{ !endsWith( env.VERSION , '-SNAPSHOT') }}
run: mvn versions:set -DnewVersion=${{ env.VERSION }}-SNAPSHOT

这些 maven 插件可以很好的替换 pom.xml 中的 version 属性。但是只是替换 version 这个功能,需要从中央仓库拉取代码,并执行整个插件流程,整体下来未免有点重。
在我浏览文档的过程中,发现在 GitHub Actions 中可以使用 python 脚本,于是重写了改地方:

- name: setting snapshot version
run: |
  import xml.etree.ElementTree as ET
  tree = ET.parse("pom.xml")
  version = tree.find("{http://maven.apache.org/POM/4.0.0}version")
  print(version.text + "-SNAPSHOT")
  if version.text.endswith("-SNAPSHOT") == False:
    tree.find("{http://maven.apache.org/POM/4.0.0}version").text = version.text + "-SNAPSHOT"
    ET.register_namespace("", "http://maven.apache.org/POM/4.0.0")
    tree.write("pom.xml", "utf-8", True)
shell: python

显著的成效是:将运行时间从之前使用 mavan 插件的 4s~17s 降低到了使用 python 脚本 0s

@zhangyd-c zhangyd-c merged commit 62cd7af into justauth:dev Sep 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants