我正在尝试使用GitHub的Actions及其对Docker容器的支持来设置一些CI测试。特别:
当发出拉取请求时,我希望GitHub Action 构建一个docker容器,并使用它从发出该拉取请求的分支中构建代码。我尝试使用$ GITHUB_REF作为输入传递分支名称。但是,所有获得的entrypoint.sh脚本实际上都是“$ GITHUB_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
name: 'DockerAction-JANA2'
description: 'Build JANA2 and run JTest plugin'
inputs:
branch: # id of input
description: 'branch name'
required: false
default: 'master'
# This specifies that docker will be used and the Dockerfile that the
# image should be built from. The args section specifies arguments that
# should be passed to the container when it is run (not when the image
# is being built).
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.branch }}
#!/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 as the only argument
# to this script. It also uses the CXX_STANDARD environment variable
# which should be set in the Dockerfile to be consistent with what
# the ROOT version used. (See Dockerfile for details.)
#
# n.b. The JANA software will be installed in /usr and the
# plugins in /plugins. This is in spite of setting the
# CMAKE_INSTALL_PREFIX below.
#
export BRANCH=$1
echo "--- Building JANA for branch $BRANCH --------------"
cd /opt/JANA2
git checkout $BRANCH
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/opt/JANA2/Linux -DCMAKE_CXX_STANDARD=$CXX_STANDARD
make -j8 install
echo "------------------------"
echo "--- JTest --------------"
export JANA_PLUGIN_PATH=/plugins
jana -PPLUGINS=JTest -Pjana:nevents=100
echo "------------------------"
echo "--- tests --------------"
export JANA_PLUGIN_PATH=/plugins
tests
echo "------------------------"
最佳答案
当您使用其他操作时,基本上可以运行其他程序。因此没有 shell 程序,因此没有什么可以解析$GITHUB_REF
env变量并将其解析为分支名称。
在with
键中,您只能使用${{ ... }}
来访问context information and evaluate expressions。github
上下文包含您要传递给faustus123/DockerAction-JANA2@alpha
操作的ref作为分支参数的输入,因此以下操作可能有效:
...
steps:
- name: Build and run
id: build_and_run
uses: faustus123/DockerAction-JANA2@alpha
with:
branch: ${{ github.head_ref }}
关于docker - GitHub Docker Action 拉取请求分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60671739/