Github操作:在/ home / runner中找不到s3cfg文件

时间:2020-04-26 08:45:26

标签: github github-actions s3cmd

在我的github动作工作流中,我想将文本文件上传到s3。在我的项目根文件夹中,我已经创建了.s3cfg文件

这是我的action.yml文件。

name: Github Action
on:
  push:
    branches:
      - fix/build

jobs:
  test:
    runs-on: ubuntu-18.04

    steps:
      - uses: actions/checkout@v1
      - name: Bootstrap app on Ubuntu
        uses: actions/setup-node@v1
        with:
          node-version: 12
      - name: Install s3cmd
        run: sudo apt install s3cmd
      - name: Install global packages
        run: npm install -g yarn

      - name: Install project deps
        run: yarn

      - name: Build the app
        run: yarn build

      - name: Upload a simple text file to s3
        run: sudo s3cmd put src/taka.txt s3://ashik-test -P


但是,我收到此错误:ERROR: /home/runner/.s3cfg: None ERROR: Configuration file not available.

我该如何解决?

1 个答案:

答案 0 :(得分:1)

您似乎不太确定在GitHub托管的VM中将存储库代码挂载/放置的位置。

来自GitHub Actions文档:
https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners(我复制粘贴的表格在下面的格式不正确,因此如果您感到困惑,请单击链接)

GitHub托管的运行程序上的文件系统GitHub执行动作和Shell 虚拟机上特定目录中的命令。文件 虚拟机上的路径不是静态的。使用环境 GitHub提供的变量用于构建主目录的文件路径, 工作区和工作流程目录。

目录环境变量说明

home HOME包含与用户相关的数据。例如,此目录 可能包含来自登录尝试的凭据。

workspace GITHUB_WORKSPACE在此执行操作和shell命令 目录。一个动作可以修改该目录的内容, 后续操作可以访问。

我只是瞥了一眼s3cmd --help

Usage: s3cmd [options] COMMAND [parameters]

S3cmd is a tool for managing objects in Amazon S3 storage. It allows for
making and removing "buckets" and uploading, downloading and removing
"objects" from these buckets.

Options:
...
  -c FILE, --config=FILE
                        Config file name. Defaults to $HOME/.s3cfg

看来s3cmd在$HOME/.s3cfg上寻找其配置文件,但是由于您的存储库位于$GITHUB_WORKSPACE,因此您的文件实际上位于:$GITHUB_WORKSPACE/.s3cfg

我尝试将-c标志与s3cmd一起使用来指定.s3cfg文件的位置。 例如:

      - name: Upload a simple text file to s3
        run: sudo s3cmd -c "$GITHUB_WORKSPACE/.s3cmd" put src/taka.txt s3://ashik-test -P
  • 顺便说一句,我不确定为什么您需要在这里使用sudo,我想您可能不需要它。
  • 提示:如果您对事物的位置感到困惑或想要以交互方式尝试事物,则可以使用GitHub操作“用tmate调试”在运行器/ VM内部“四处探寻”。 https://github.com/marketplace/actions/debugging-with-tmate