update-version.yml 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. name: update version and sync-repo
  2. on:
  3. push:
  4. branches:
  5. - master # 监听主分支代码提交事件
  6. jobs:
  7. update-version:
  8. runs-on: ubuntu-latest
  9. steps:
  10. - name: Checkout code
  11. uses: actions/checkout@v2
  12. - name: Update version
  13. run: |
  14. # 读取当前版本号
  15. current_version=$(cat VERSION)
  16. # 提取版本号中的年份部分和当年版本序号
  17. version_year=${current_version:1:4}
  18. version_number=${current_version:5:3}
  19. # 获取当前年份
  20. current_year=$(date +'%Y')
  21. # 判断版本号年份是否是当前年份
  22. if [ "$version_year" = "$current_year" ]; then
  23. # 当年版本号加1
  24. new_version_number=$(printf "%03d" $((10#$version_number + 1)))
  25. else
  26. # 如果不是当前年份,则重置为001
  27. new_version_number="001"
  28. fi
  29. # 生成新的版本号
  30. new_version="V${current_year}${new_version_number}"
  31. # 更新版本号到文件
  32. echo $new_version > VERSION
  33. - name: Commit changes
  34. run: |
  35. git config --local user.email "action@github.com"
  36. git config --local user.name "GitHub Action"
  37. git commit -m "Update version to $new_version" -a
  38. git push origin master
  39. - name: sync-repo
  40. uses: yesolutions/mirror-action@master
  41. with:
  42. REMOTE: 'https://git.pig4cloud.com/pig/CGTM.git'
  43. GIT_USERNAME: lengleng
  44. GIT_PASSWORD: ${{ secrets.GIT_GOGS_PASSWORD }}