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

Support hashing files outside the workspace directory #1035

Open
PeterJCLaw opened this issue Mar 28, 2022 · 7 comments
Open

Support hashing files outside the workspace directory #1035

PeterJCLaw opened this issue Mar 28, 2022 · 7 comments
Labels
enhancement New feature or request

Comments

@PeterJCLaw
Copy link

PeterJCLaw commented Mar 28, 2022

Currently hashFiles ignores files outside the workspace. This means that it cannot be used to hash files which appear within an Action. In turn this means that packages such as actions/setup-python cannot be used with files from the Action (see for example actions/setup-python#361), making them hard to use within composite Actions.

It would be great if hashFiles could support these files as it would enable more powerful composite Actions.

@fjelliott
Copy link

I also would like to see this issue resolved. I am also having issues with caching with actions/setup-python#361 in a composite action. The maintainer of that action says that this bug can't be fixed until the issue in this repository is resolved.

@flobernd
Copy link

Same scenario for me: actions/setup-python inside a composite action.

As a workaround I have to copy the scripts to the workspace directory. Not a super nice solution tho (there might already be a directory with the same name and so on..):

- name: Set up Scripts
  id: setup-scripts
  shell: bash
  run: |
    SCRIPTS_PATH="$GITHUB_WORKSPACE/scripts"
    cp -r "${{ github.action_path }}/../../scripts" "$SCRIPTS_PATH"
    echo "SCRIPTS_PATH=$SCRIPTS_PATH" >> $GITHUB_ENV
    echo "::set-output name=scripts-path::$(echo $SCRIPTS_PATH)"

@jappi00
Copy link

jappi00 commented Jun 23, 2023

Same problem here

@alexkuc
Copy link

alexkuc commented Aug 15, 2023

Perhaps I am missing something but this feature is already implemented?

export async function hashFiles(
globber: Globber,
currentWorkspace: string,
verbose: Boolean = false
): Promise<string> {

Initially, when I used the function with just globber parameter, I got exactly the same behaviour as described above. But after specifying currentWorkspace parameter, I was able to hash files outside of GITHUB_WORKSPACE.

@PeterJCLaw
Copy link
Author

Huh, it looks like that changed since this was reported. The originally linked code was

if (!file.startsWith(`${githubWorkspace}${path.sep}`)) {
core.debug(`Ignore '${file}' since it is not under GITHUB_WORKSPACE.`)
continue
}

It seems that the equivalent check is still present

if (!file.startsWith(`${githubWorkspace}${path.sep}`)) {
writeDelegate(`Ignore '${file}' since it is not under GITHUB_WORKSPACE.`)
continue
}

Though as @alexkuc notes there is now a way to set what the "workspace" is. This could potentially be used by other Actions to specify themselves as the "workspace", though seems perhaps an unintended consequence. (The change was in #1318).

@alexkuc
Copy link

alexkuc commented Aug 16, 2023

Curiously enough, there is no official documentation for hashFiles(). Although, there is a closed issue and a closed PR that adds this function.

@h0tw1r3
Copy link

h0tw1r3 commented Apr 22, 2024

Until hashFiles works outside of the workspace (in a composite), here's an example of the work-around I came up with:

runs:
  steps:
    - uses: actions/setup-python@v5
      id: setup-python
      with:
        python-version: '3.10'
        update-environment: false
        
    - uses: actions/github-script@v7
      id: requirements-hash
      with:
        script: return require('fs').createReadStream(require('path').join(process.env.GITHUB_ACTION_PATH, 'requirements.txt')).pipe(require('crypto').createHash('sha1').setEncoding('hex'), 'finish').digest('hex')
        result-encoding: string

    - uses: actions/cache@v4
      with:
        key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ steps.requirements-hash.outputs.result }}
        restore-keys: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-
        path: ${{ github.action_path }}/venv
        
    - name: Setup python venv
      shell: bash
      run: |
        ${{ steps.setup-python.outputs.python-path }} -m venv "$GITHUB_ACTION_PATH/venv"
        source "$GITHUB_ACTION_PATH/venv/bin/activate"
        pip install -r "$GITHUB_ACTION_PATH/requirements.txt"

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

6 participants