【问题标题】:How do you write a cmake.yml which allows you to review a file on GitHub?您如何编写允许您在 GitHub 上查看文件的 cmake.yml?
【发布时间】:2022-02-04 02:26:45
【问题描述】:

我编写了一个程序,它接受一个包含输入文件的命令行参数,并通过一些算法运行它并创建一个包含结果的 txtfile。

我需要做的是使用 GitHub Actions 查看文件。我的程序是使用 GitHub Actions 构建的,但我无法查看输出文件。

目前这是我设置 cmake.yml 的方式:


on:
  push:
    branches: [ main ]

env:
  BUILD_TYPE: Debug
  file's
  TEST_EXE: 22s_pa01_nicandpaige
  INPUT_FILE: input/input.txt
  OUTPUT_FILE: output/test-highvalue.txt output/test-custom.txt. output/test-bruteforce



jobs:
  build:
    runs-on: ubuntu-latest
    timeout-minutes: 3

    steps:
      - uses: actions/checkout@v2

      - name: Configure CMake
        run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

      - name: Build
        run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}


      - name: Execute Project
        working-directory: ${{github.workspace}}/build
        run: ${{github.workspace}}/build/${{env.TEST_EXE}} ${{env.INPUT_FILE}} ${{env.OUTPUT_FILE}}

      - name: Upload output files to GitHub so they can be reviewed
        uses: actions/upload-artifact@v2
        with:
          name: project_output
          path: ${{github.workspace}}/build/output

关于我如何在程序中编写文本文件:

std:: ofstream myfile;
    myfile.open ("../output/test-highvalue.txt");
    for (auto & i : x){
        myfile << i.getId();
        myfile << " ";
        myfile << i.getValue();
        totalValue += i.getValue();
        myfile << " ";
        myfile << i.getLength();
        myfile << " ";
        myfile << i.getH();
        myfile << std:: endl;
    }

以下代码跨三个不同的类复制并在 main 中调用。

至于我们如何调用输入文件:

std::vector<paintingData> read_paintings(char* arg){
    std::ifstream inFS(arg);
    if(!inFS.is_open()){
        std::cout << "Failed to open " << arg << std::endl;
        return std::vector<paintingData>();
    }

这个函数比这个更广泛,但它在 main 中被调用,数据被传递给必要的算法。

虽然它正在构建,但当我仔细查看构建时,我会收到以下消息

请使用包含的输入文件名作为参数执行此程序。

警告:未找到具有以下路径的文件:/home/runner/work/22s-pa01-nicandpaige/22s-pa01-nicandpaige/build/output。不会上传任何工件。

我不确定问题出在哪里,因为这是我第一次编写 cmake.yml,我遇到了障碍。

任何指导将不胜感激。

【问题讨论】:

  • 你确定你的 yaml 文件在语法上是正确的吗?我偶然发现了“文件”行,即恕我直言无效的 yaml。

标签: github cmake file-io yaml github-actions


【解决方案1】:

这似乎是您的程序发出的错误消息:

请使用包含的输入文件名作为参数执行此程序。

我们无法知道出了什么问题,因为您没有显示发出此问题的程序部分。

你说

我写了一个程序,它接受一个命令行参数

但是你给出了多个参数:

${{env.INPUT_FILE}} ${{env.OUTPUT_FILE}}

你显示代码行

myfile.open ("../output/test-highvalue.txt");

您的工作目录是${{github.workspace}}/build,因此您的输出目录是${{github.workspace}}/output,而不是${{github.workspace}}/build/output

您没有展示如何创建output 目录。

总结:有一些可疑的事情,但你没有提供足够的信息让我们真正找出问题所在。

【讨论】:

  • 感谢您的反馈!我将编辑这篇文章以包含该信息。
  • 经过进一步检查,您对目录的评论似乎是问题所在。此问题现已解决
猜你喜欢
  • 2021-08-27
  • 2022-01-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-16
  • 2017-08-18
  • 2012-04-06
相关资源
最近更新 更多