使用 github actions 进行版本自动化时,我收到加载 RSA 密钥的错误

问题描述 投票:0回答:1

我的主要想法是,每次我进行提交时,它都会查看短语 NEW_VERSION:5.0.01 (5.0.01 只是本例中的一个示例)是否存在于提交消息中的某个位置,并将其替换为常量新版本。 这是我在 .yml 中的代码:

name: Update Version

on:
  push:
    branches:
      - main

jobs:
  update-version:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v2
        with:
          fetch-depth: 0

      - name: Configure SSH
        run: |
          mkdir -p ~/.ssh
          echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
          chmod 600 ~/.ssh/id_rsa
          ssh-keyscan github.com >> ~/.ssh/known_hosts
          git config --global user.email "[email protected]"
          git config --global user.name "joaovitorkc"

      - name: Start SSH agent
        run: eval `ssh-agent -s`

      - name: Install Node.js
        uses: actions/setup-node@v2
        with:
          node-version: '14'

      - name: Get last commit message
        id: last_commit
        run: echo "::set-output name=message::$(git log -1 --pretty=%B)"

      - name: Extract version from commit message
        id: extract_version
        run: echo "::set-output name=version::$(echo ${{ steps.last_commit.outputs.message }} | grep -oP 'NEW_VERSION:\K\d+\.\d+\.\d+')"

      - name: Update version constant in code
        run: |
          if [ -n "${{ steps.extract_version.outputs.version }}" ]; then
            sed -i "s/const VERSION = \".*\";/const VERSION = \"${{ steps.extract_version.outputs.version }}\";/" src/libs/version.ts
            echo "Version updated to ${{ steps.extract_version.outputs.version }}"
          else
            echo "No new version found in commit message."
          fi

      - name: Commit and push updated version
        env:
          SSH_AUTH_SOCK: /tmp/ssh_agent.sock
        run: |
          ssh-add ~/.ssh/id_rsa
          git commit -am "Update version to ${{ steps.extract_version.outputs.version }}"
          git push

但是当这段代码在 github actions 中运行时,会出现以下错误:

有错误的图像

错误详情

github automation github-actions
1个回答
0
投票

您无需配置 SSH。您使用 HTTPS 检查了您的存储库。试试这个:

     run: |
      git commit -am "Update version to ${{ steps.extract_version.outputs.version }}"
      git push
© www.soinside.com 2019 - 2024. All rights reserved.