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 · 1 comment
Open

Clear working directory between runs? #3854

TaxBusby opened this issue Apr 19, 2024 · 1 comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants