Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear working directory between runs? #3854

Open
TaxBusby opened this issue Apr 19, 2024 · 2 comments
Open

Clear working directory between runs? #3854

TaxBusby opened this issue Apr 19, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@TaxBusby
Copy link

Hi there, I'm using the non-ephemeral runners, which is fine with me for performance/isolation tradeoff.

However, it looks like the working directory given to workflows does not get cleared between jobs. This can lead to surprise for developers who expect a clean working directory.

Is there an option available to have the runners clear the working directory between runs?


Here's a short workflow I'm using to test this case:

name: Ephemerality Test
on:
  workflow_dispatch:

jobs:
  write:
    runs-on: [self-hosted]
    name: Write
    steps:
      - name: Write files
        run: |
          echo Current Directory: $(pwd)
          ls
          echo "Local File Exists" > hello.txt
          echo "Temp File Exists" > /tmp/hello.txt
          
  read:
    runs-on: [self-hosted]
    needs: [write]
    name: Read
    steps:
      - name: Test for persisted files
        run: |
          echo Current Directory: $(pwd)
          ls
          cat hello.txt || echo "Local dir cleared"
          cat /tmp/hello.txt || echo "Tmp dir cleared"
          
          if [ -f hello.txt ]; then
              echo "Local file was not cleared!"
              exit 1
          fi
          if [ -f /tmp/hello.txt ]; then
              echo "Temp file was not cleared!"
              exit 1
          fi

Outputs:

// Write
Current Directory: /opt/actions-runner/_work/gh-self-hosted-runners/gh-self-hosted-runners
hello.txt

// Read
Current Directory: /opt/actions-runner/_work/gh-self-hosted-runners/gh-self-hosted-runners
hello.txt
Local File Exists
Temp File Exists
Local file was not cleared!
@sykhro
Copy link

sykhro commented May 20, 2024

This is the standard behaviour when using self-hosted runners with GitHub Actions. You are responsible for cleanup in your own workflows

@winwinashwin
Copy link
Contributor

From their blog post, github seems to recommend using pre/post job hooks for cleanup. Currently the terraform does not allow the user to override or extend the pre job hook created by the terraform.

  1. The pre job script is overridden and not appended to.
  2. The script does not execute any additional user configurable scripts.
  3. The start-runner.sh is executed after both pre and post user-data scripts which the user can provide as inputs to the terraform.

All these make it really difficult to extend the pre job hook.

@npalm Can we add a feature where the user can extend or replace the pre job script?

@stuartp44 stuartp44 added the enhancement New feature or request label Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants