首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在github操作期间使用git命令?

如何在github操作期间使用git命令?
EN

Stack Overflow用户
提问于 2020-07-18 03:20:49
回答 1查看 4.5K关注 0票数 2

尝试在自托管运行器上执行pull请求期间,使用github操作将黑色和isort自动应用于某些python代码上更改的文件,然后提交给PR。但在某些步骤中会出现诸如Not a git repository之类的错误。这是我的工作流文件:

代码语言:javascript
复制
name: Autolint

on:
  pull_request:
    types: [opened, synchronize]

jobs:
  run-linters:
    name: Run linters
    runs-on: self-hosted
    container:
      image: edlut/azion:monster-action-base
      options: --privileged

    steps:
    - name: Install git 
      run: |
        apt-get install -y git
        git --version
        echo "Path is ... $PATH"
        PATH=$PATH:$(which git)
        echo "Path is ... $PATH"

    - uses: actions/checkout@v2

    - name: Debug - Check if .git folder exists
      run: |
        ls -lah

    - name: Install Python dependencies
      run: pip3 install black isort

    - name: Apply Black
      env:
        BRANCH: ${{ github.head_ref }}
      run: |
        echo "Branch is ... ${BRANCH}"
        git diff --name-only "$GITHUB_BASE_REF..${BRANCH}" | grep .py | xargs black -l 119

    - name: Apply isort
      env:
        BRANCH: ${{ github.head_ref }}
      run: |
        git diff --name-only "$GITHUB_BASE_REF..${BRANCH}" | xargs isort

    - name: Check for modified files
      id: git-check
      run: echo ::set-output name=modified::$(if git status | grep "nothing to commit"; then echo "false"; else echo "true"; fi)

    - name: Push changes
      if: steps.git-check.outputs.modified == 'true'
      run: |
        git config --global user.name 'My Name'
        git config --global user.email 'my-name@gmail.com'
        git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
        # git commit -am "style: Apply Black style"
        # git push

有谁能帮我解决这个问题吗?

EN

回答 1

Stack Overflow用户

发布于 2021-08-19 00:45:33

代码语言:javascript
复制
name: Version Build

on:
  push:
    branches: [ develop ]

jobs:
  build-version:

    runs-on: ubuntu-latest

    steps:
    - name: Git checkout
      uses: actions/checkout@v2
      with:
        fetch-depth: '0'
    - name: git
      run: |
        # setup the username and email. I tend to use 'GitHub Actions Bot' with no email by default
        git --version
        git config user.name "GitHub Actions Bot"
        git config user.email "<>"
        git status
        git tag
        git describe
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62960533

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档