docker - GitHub Docker Action 拉取请求分支

标签 docker github-actions

我正在尝试使用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/

相关文章:

reactjs - Azure React应用程序 'You do not have permission to view this directory or page'

python - 在 Docker 中运行的 Aiohttp 和 NGINX

Docker 在 "ENV"中找不到 = 必须采用 : name=value 形式

docker - 访问嵌套的 Docker

node.js - 在 Nodejs 的 azure github 操作中使用工件

github-actions - 如何检查 github 操作条件中的标签

github-actions - Github 贡献网格蛇显示错误

python-3.x - 无法通过api访问dockerized python azure函数?

macos - 在启动时启动docker-machine

node.js - 如何在 GitHub Actions/Workflows 配置中安装 imagemagick 和其他自制软件依赖项?