【发布时间】:2020-06-25 13:04:37
【问题描述】:
我正在尝试使用 GitHub 的 Actions 及其对 Docker 容器的支持来设置一些 CI 测试。具体来说:
发出拉取请求时,我希望 GitHub 操作构建一个 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 "------------------------"
【问题讨论】:
-
stackoverflow.com/a/60348455/225291 可能会有所帮助。
标签: docker github-actions