GitHub Docker操作拉请求分支

GitHub Docker操作拉请求分支,docker,github-actions,Docker,Github Actions,我正在尝试使用GitHub的操作及其对Docker容器的支持来设置一些CI测试。具体而言: 当发出拉请求时,我希望GitHub操作构建一个docker容器,并使用它从发出拉请求的分支构建代码。我尝试使用$GITHUB\u REF作为输入来传递分支名称。但是,entrypoint.sh脚本得到的所有内容都是“$GITHUB\u REF”,而不是解析的分支名称 以下是相关文件: name: C/C++ CI docker on: push: branches: [ master ]

我正在尝试使用GitHub的操作及其对Docker容器的支持来设置一些CI测试。具体而言:

当发出拉请求时,我希望GitHub操作构建一个docker容器,并使用它从发出拉请求的分支构建代码。我尝试使用$GITHUB\u REF作为输入来传递分支名称。但是,entrypoint.sh脚本得到的所有内容都是“$GITHUB\u REF”,而不是解析的分支名称

以下是相关文件:

name: C/C++ CI docker

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  JTest_job:

    runs-on: ubuntu-latest
    name: Full build with tests

    # Build Docker container and run the entrypoint.sh script in it
    steps:
    - name: Build and run
      id: build_and_run
      uses: faustus123/DockerAction-JANA2@alpha
      with:
        branch: $GITHUB_REF

当你使用另一个动作时,你基本上运行了一个不同的程序。因此没有shell,因此任何东西都无法解析
$GITHUB\u REF
env变量并将其解析为分支名称

在带有键的
中,您只能使用
${{…}访问

github
上下文包含要传递给
faustus123/DockerAction的ref-JANA2@alpha
操作作为分支参数的输入,因此以下操作可能有效:

...
  steps:
  - name: Build and run
    id: build_and_run
    uses: faustus123/DockerAction-JANA2@alpha
    with:
      branch: ${{ github.head_ref }}

当你使用另一个动作时,你基本上运行了一个不同的程序。因此没有shell,因此任何东西都无法解析
$GITHUB\u REF
env变量并将其解析为分支名称

在带有键的
中,您只能使用
${{…}访问

github
上下文包含要传递给
faustus123/DockerAction的ref-JANA2@alpha
操作作为分支参数的输入,因此以下操作可能有效:

...
  steps:
  - name: Build and run
    id: build_and_run
    uses: faustus123/DockerAction-JANA2@alpha
    with:
      branch: ${{ github.head_ref }}

@banyan给出的参考给出了与@zCHIP的答案类似的信息,这是获取参数所需的信息。基本上,传递${github.ref}。它不包含实际的分支名称,而是一个类似“refs/pull/61/head”的引用。然后,我的entrypoint.sh脚本需要将其提取到一个分支(本地)中,然后可以将其签出

尽管如此,我还是注意到当docker容器运行时,GitHub确实会传入GitHub_REF环境变量,这实际上意味着我自己不必麻烦将其作为参数传递。我清理了一些文件,这里是我的最终版本,它似乎可以在其他人试图这样做的情况下工作

这是我实际项目中的动作脚本ccpp-docker.yml,我想为其实现CI:

name: C/C++ CI docker

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  JTest_job:

    runs-on: ubuntu-latest
    name: Full build with tests

    # Build Docker container and run the entrypoint.sh script in it
    steps:
    - name: Build and run
      id: build_and_run
      uses: faustus123/DockerAction-JANA2@alpha
以下是我的自定义操作中的action.yml脚本,该脚本托管在专用的faustus123/DockerAction-JANA2存储库中

#
# This specifies a custom GitHub action that is used to
# build a Docker image as part of the JANA2 CI.
#


name: 'DockerAction-JANA2'
description: 'Build JANA2 and run JTest plugin'

# This specifies that docker will be used and the Dockerfile that the
# image should be built from.
runs:
  using: 'docker'
  image: 'Dockerfile'
#!/bin/bash
#
# This is run from within the temporary janatest container
# that gets built by GitHub as part of a GitHub Action to test
# pull requests and commits to master.
#
# This builds JANA2 using the branch given by the GITHUB_REF
# environment variable (passed in by GitHub when container
# is run). What actually gets passed is not the branch
# name, but a repository reference from GITHUB_REF that looks
# something like "refs/pull/61/merge". This gets fetched from the
# origin into a branch named "CI" which is then checked out.
#
# This also uses the CXX_STANDARD environment variable
# which should be set in the Dockerfile to be consistent with
# whatever the ROOT version used. (See Dockerfile for details.)


echo "--- Checking out JANA for $GITHUB_REF --------------"
cd /opt/JANA2
git fetch origin ${GITHUB_REF}:CI
git checkout CI

echo "--- Building JANA ------------------------------"
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/opt/JANA2/Linux -DCMAKE_CXX_STANDARD=$CXX_STANDARD
make -j8 install

echo "--- Setting up JANA environment ----------------"
export PATH=/opt/JANA2/Linux/bin:${PATH}
export JANA_PLUGIN_PATH=/opt/JANA2/Linux/plugins
echo "PATH=${PATH}"
echo "JANA_PLUGIN_PATH=${JANA_PLUGIN_PATH}"

echo "--- Running JTest plugin -----------------------"
jana -PPLUGINS=JTest -Pjana:nevents=100

echo "--- Running janatests ------------------------------"
janatests

echo "--- Done ---------------------------------------"
下面是entrypoint.sh脚本,它托管在专用的faustus123/DockerAction-JANA2存储库中

#
# This specifies a custom GitHub action that is used to
# build a Docker image as part of the JANA2 CI.
#


name: 'DockerAction-JANA2'
description: 'Build JANA2 and run JTest plugin'

# This specifies that docker will be used and the Dockerfile that the
# image should be built from.
runs:
  using: 'docker'
  image: 'Dockerfile'
#!/bin/bash
#
# This is run from within the temporary janatest container
# that gets built by GitHub as part of a GitHub Action to test
# pull requests and commits to master.
#
# This builds JANA2 using the branch given by the GITHUB_REF
# environment variable (passed in by GitHub when container
# is run). What actually gets passed is not the branch
# name, but a repository reference from GITHUB_REF that looks
# something like "refs/pull/61/merge". This gets fetched from the
# origin into a branch named "CI" which is then checked out.
#
# This also uses the CXX_STANDARD environment variable
# which should be set in the Dockerfile to be consistent with
# whatever the ROOT version used. (See Dockerfile for details.)


echo "--- Checking out JANA for $GITHUB_REF --------------"
cd /opt/JANA2
git fetch origin ${GITHUB_REF}:CI
git checkout CI

echo "--- Building JANA ------------------------------"
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/opt/JANA2/Linux -DCMAKE_CXX_STANDARD=$CXX_STANDARD
make -j8 install

echo "--- Setting up JANA environment ----------------"
export PATH=/opt/JANA2/Linux/bin:${PATH}
export JANA_PLUGIN_PATH=/opt/JANA2/Linux/plugins
echo "PATH=${PATH}"
echo "JANA_PLUGIN_PATH=${JANA_PLUGIN_PATH}"

echo "--- Running JTest plugin -----------------------"
jana -PPLUGINS=JTest -Pjana:nevents=100

echo "--- Running janatests ------------------------------"
janatests

echo "--- Done ---------------------------------------"

@banyan给出的参考给出了与@zCHIP的答案类似的信息,这是获取参数所需的信息。基本上,传递${github.ref}。它不包含实际的分支名称,而是一个类似“refs/pull/61/head”的引用。然后,我的entrypoint.sh脚本需要将其提取到一个分支(本地)中,然后可以将其签出

尽管如此,我还是注意到当docker容器运行时,GitHub确实会传入GitHub_REF环境变量,这实际上意味着我自己不必麻烦将其作为参数传递。我清理了一些文件,这里是我的最终版本,它似乎可以在其他人试图这样做的情况下工作

这是我实际项目中的动作脚本ccpp-docker.yml,我想为其实现CI:

name: C/C++ CI docker

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  JTest_job:

    runs-on: ubuntu-latest
    name: Full build with tests

    # Build Docker container and run the entrypoint.sh script in it
    steps:
    - name: Build and run
      id: build_and_run
      uses: faustus123/DockerAction-JANA2@alpha
以下是我的自定义操作中的action.yml脚本,该脚本托管在专用的faustus123/DockerAction-JANA2存储库中

#
# This specifies a custom GitHub action that is used to
# build a Docker image as part of the JANA2 CI.
#


name: 'DockerAction-JANA2'
description: 'Build JANA2 and run JTest plugin'

# This specifies that docker will be used and the Dockerfile that the
# image should be built from.
runs:
  using: 'docker'
  image: 'Dockerfile'
#!/bin/bash
#
# This is run from within the temporary janatest container
# that gets built by GitHub as part of a GitHub Action to test
# pull requests and commits to master.
#
# This builds JANA2 using the branch given by the GITHUB_REF
# environment variable (passed in by GitHub when container
# is run). What actually gets passed is not the branch
# name, but a repository reference from GITHUB_REF that looks
# something like "refs/pull/61/merge". This gets fetched from the
# origin into a branch named "CI" which is then checked out.
#
# This also uses the CXX_STANDARD environment variable
# which should be set in the Dockerfile to be consistent with
# whatever the ROOT version used. (See Dockerfile for details.)


echo "--- Checking out JANA for $GITHUB_REF --------------"
cd /opt/JANA2
git fetch origin ${GITHUB_REF}:CI
git checkout CI

echo "--- Building JANA ------------------------------"
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/opt/JANA2/Linux -DCMAKE_CXX_STANDARD=$CXX_STANDARD
make -j8 install

echo "--- Setting up JANA environment ----------------"
export PATH=/opt/JANA2/Linux/bin:${PATH}
export JANA_PLUGIN_PATH=/opt/JANA2/Linux/plugins
echo "PATH=${PATH}"
echo "JANA_PLUGIN_PATH=${JANA_PLUGIN_PATH}"

echo "--- Running JTest plugin -----------------------"
jana -PPLUGINS=JTest -Pjana:nevents=100

echo "--- Running janatests ------------------------------"
janatests

echo "--- Done ---------------------------------------"
下面是entrypoint.sh脚本,它托管在专用的faustus123/DockerAction-JANA2存储库中

#
# This specifies a custom GitHub action that is used to
# build a Docker image as part of the JANA2 CI.
#


name: 'DockerAction-JANA2'
description: 'Build JANA2 and run JTest plugin'

# This specifies that docker will be used and the Dockerfile that the
# image should be built from.
runs:
  using: 'docker'
  image: 'Dockerfile'
#!/bin/bash
#
# This is run from within the temporary janatest container
# that gets built by GitHub as part of a GitHub Action to test
# pull requests and commits to master.
#
# This builds JANA2 using the branch given by the GITHUB_REF
# environment variable (passed in by GitHub when container
# is run). What actually gets passed is not the branch
# name, but a repository reference from GITHUB_REF that looks
# something like "refs/pull/61/merge". This gets fetched from the
# origin into a branch named "CI" which is then checked out.
#
# This also uses the CXX_STANDARD environment variable
# which should be set in the Dockerfile to be consistent with
# whatever the ROOT version used. (See Dockerfile for details.)


echo "--- Checking out JANA for $GITHUB_REF --------------"
cd /opt/JANA2
git fetch origin ${GITHUB_REF}:CI
git checkout CI

echo "--- Building JANA ------------------------------"
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/opt/JANA2/Linux -DCMAKE_CXX_STANDARD=$CXX_STANDARD
make -j8 install

echo "--- Setting up JANA environment ----------------"
export PATH=/opt/JANA2/Linux/bin:${PATH}
export JANA_PLUGIN_PATH=/opt/JANA2/Linux/plugins
echo "PATH=${PATH}"
echo "JANA_PLUGIN_PATH=${JANA_PLUGIN_PATH}"

echo "--- Running JTest plugin -----------------------"
jana -PPLUGINS=JTest -Pjana:nevents=100

echo "--- Running janatests ------------------------------"
janatests

echo "--- Done ---------------------------------------"
也许会有帮助。也许会有帮助。