Search code examples
githubgithub-actionss3cmd

Github Action: s3cfg file is not found in /home/runner


In my github action workflow, I want to upload a text file to s3. in my projects root folder I have created .s3cfg file

this is my action.yml file.

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


but, I am getting this error: ERROR: /home/runner/.s3cfg: None ERROR: Configuration file not available.

How can I fix this?


Solution

  • Looks like you're not quite sure where your repository code is mounted/placed in your GitHub hosted VM.

    From the GitHub Actions Docs:
    https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners (the table I copied and pasted doesn't format well below so if you're confused, click on the link)

    Filesystems on GitHub-hosted runners GitHub executes actions and shell commands in specific directories on the virtual machine. The file paths on virtual machines are not static. Use the environment variables GitHub provides to construct file paths for the home, workspace, and workflow directories.

    Directory Environment variable Description

    home HOME Contains user-related data. For example, this directory could contain credentials from a login attempt.

    workspace GITHUB_WORKSPACE Actions and shell commands execute in this directory. An action can modify the contents of this directory, which subsequent actions can access.

    I just glanced at 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
    

    It looks like s3cmd is looking for its configuration file at $HOME/.s3cfg, but since your repository is located at $GITHUB_WORKSPACE your file is really located at: $GITHUB_WORKSPACE/.s3cfg

    I would try using the -c flag with s3cmd to specify the location of your .s3cfg file. Ex:

          - name: Upload a simple text file to s3
            run: sudo s3cmd -c "$GITHUB_WORKSPACE/.s3cmd" put src/taka.txt s3://ashik-test -P
    
    • btw I'm not sure why you need to use sudo here, my guess is you probably don't need it.
    • Tip: You can use the GitHub action "Debugging with tmate" to "poke around" inside your runner/VM if you're confused about where things are or if you want to interactively try things. https://github.com/marketplace/actions/debugging-with-tmate