GitHub Action部署阶段报错:Author identity unknown问题求助
解决方案
这个错误和GITHUB_TOKEN无关,核心原因是GitHub Actions的runner环境未配置git提交所需的用户身份信息,同时你的配置里还有一个拼写错误:
1. 配置git用户身份
在执行git commit前,必须先设置git的用户名和邮箱。推荐使用GitHub官方的机器人身份,在Commit and Push Semantic Snapshot Version步骤的run命令开头添加以下配置:
git config --local user.name "github-actions[bot]" git config --local user.email "github-actions[bot]@users.noreply.github.com"
2. 修正GITHUB_TOKEN的拼写错误
你在env中写的GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}t多了末尾的t,这会导致token无效,需要改为:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
修改后的完整deploy任务
deploy: needs: test # Runs when 'test' job is completed runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Set up JDK 20 uses: actions/setup-java@v3 with: java-version: '20' distribution: 'adopt' cache: 'maven' - name: Read Current Snapshot Version id: read_snapshot_version run: echo ::set-output name=current_snapshot_version::$(grep -oPm1 "(?<=<version>)[^<]+" pom.xml | grep -E "SNAPSHOT") - name: Semantic Versioning for Snapshot id: update_snapshot_version run: | current_snapshot_version="${{ steps.read_snapshot_version.outputs.current_snapshot_version }}" IFS='.' read -r -a version_parts <<< "$current_snapshot_version" major="${version_parts[0]}" minor="${version_parts[1]}" patch="${version_parts[2]}" # When the last digit is 100 if [[ "$patch" == "100" ]]; then minor=$((minor + 1)) # Increase minor version number patch="0" # Reset last digit else patch=$((patch + 1)) fi new_snapshot_version="${major}.${minor}.${patch}-SNAPSHOT" echo "::set-output name=new_snapshot_version::${new_snapshot_version}" sed -i "s/<version>.*-SNAPSHOT<\/version>/<version>${new_snapshot_version}<\/version>/" pom.xml - name: Commit and Push Semantic Snapshot Version run: | git config --local user.name "github-actions[bot]" git config --local user.email "github-actions[bot]@users.noreply.github.com" git commit -am "SNAPSHOT version to ${{ steps.update_snapshot_version.outputs.new_snapshot_version }}" git push origin HEAD:main env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
内容的提问来源于stack exchange,提问作者omerkarabas
相关产品推荐
相关产品推荐

