{"id":17093022,"url":"https://github.com/peter-murray/reset-workspace-ownership-action","last_synced_at":"2025-04-12T22:45:09.979Z","repository":{"id":65161272,"uuid":"315688277","full_name":"peter-murray/reset-workspace-ownership-action","owner":"peter-murray","description":null,"archived":false,"fork":false,"pushed_at":"2023-02-21T05:51:27.000Z","size":21,"stargazers_count":25,"open_issues_count":2,"forks_count":5,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-26T16:55:02.988Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/peter-murray.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-11-24T16:21:22.000Z","updated_at":"2025-02-08T14:46:42.000Z","dependencies_parsed_at":"2024-06-19T09:33:44.401Z","dependency_job_id":"324e350b-7c2e-4d40-8c8d-53001efce909","html_url":"https://github.com/peter-murray/reset-workspace-ownership-action","commit_stats":{"total_commits":19,"total_committers":3,"mean_commits":6.333333333333333,"dds":"0.26315789473684215","last_synced_commit":"d25b5dda3a67e682272796c2fd97d7eb58a9246e"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peter-murray%2Freset-workspace-ownership-action","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peter-murray%2Freset-workspace-ownership-action/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peter-murray%2Freset-workspace-ownership-action/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peter-murray%2Freset-workspace-ownership-action/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peter-murray","download_url":"https://codeload.github.com/peter-murray/reset-workspace-ownership-action/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248339285,"owners_count":21087215,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T14:04:16.225Z","updated_at":"2025-04-12T22:45:09.922Z","avatar_url":"https://github.com/peter-murray.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# reset-workspace-ownership-action\n\nA GitHub Action that can be utilized to reset ownership on directories and files in the `GITHUB_WORKSPACE` that can result from \nusing Containers in GitHub Actions Workflows on self-hosted runners.\n\n\n## Problem\n\nWhen using self-hosted runners with GitHub Actions the action runners have a persistence across workflow jobs and workflows that\ncan sometime be tripped up by using containers as part of your workflows.\n\nAny container that outputs files or directories will create them within the `GITHUB_WORKSPACE` directory with the owner set to that\nof the `USER` in the container that being executed unless you are performing a user and/or group remapping when starting the container.\n\nTypically this can result in files being present inside the `GITHUB_WORKSPACE` directory that are owned by `root` and it is not common to\nbe running the GitHub Actions runner as the root user (you can do so, but it is discouraged).\n\nWhen you then execute another workflow on the repository that has some of the files present in the `GITHUB_WORKSPACE` you will typically encounter\na problem with the `actions/checkout@v2` action failing as it cannot clean up the `GITHUB_WORKSPACE` directory at the beginning of the following\nworkflow execution.\n\n\n## A Workaround Solution\n\nTo resolve this problem and prevent it from breaking a future workflow invocation, you can utilize the action to detect and correct the directories \nand files that are not currently owned by the same user that the GitHub Actions runner is running as.\n\nThis GitHub Action is a Docker based Action that will mount the `GITHUB_WORKSPACE` and then look for any directories or files not owned by the specifed\nuser UID and then change the ownership to the provided UID.\n\nTo do this it uses the smallest possible container with a bash environment to be able to detect and fix these ownership issues so as to not add much overhead\nto any workflow executions. It has to be a Docker container, as it runs as `root` inside the container to be able to perform these ownership changes.\n\n\n## Parameters\n\n* `user_id`: The UID of the user that the GitHub Actions runner is running as. This will be the UID that will be used to modify any files or directories\n  that do not currently have this UID as the owner. This needs to be a UID number and not a name, as the container will not necessarily have a user inside it\n  that will resolve to a valid user.\n\nNote that you need to already know the UID for the GitHub Actions runner, or be able to reference it from the environment. You cannot do this as part of this \naction, as this action is Docker based and does not have access to the runner's environment when it runs.\n\nYou can utilize an action step like the following to expose the UID of the GitHub Actions runner so it can be referenced as an Action Step Output:\n\n```\n- name: Get Actions user id\n  id: get_uid\n  run: |\n    actions_user_id=`id -u $USER`\n    echo $actions_user_id\n    echo \"uid=$actions_user_id\" \u003e\u003e $GITHUB_OUTPUT\n```\n\n\n## Examples\n\nObtain the UID of the GitHub Actions runner and then correct any directories and files that are not owned by the runner.\n\n```\n- name: Get Actions user id\n  id: get_uid\n  run: |\n    actions_user_id=`id -u $USER`\n    echo $actions_user_id\n    echo \"uid=$actions_user_id\" \u003e\u003e $GITHUB_OUTPUT\n\n- name: Correct Ownership in GITHUB_WORKSPACE directory\n  uses: peter-murray/reset-workspace-ownership-action@v1\n  with:\n    user_id: ${{ steps.get_uid.outputs.uid }}\n```\n\n## Action Logs\n\nWhen the action is run it will log the files adn directories it detects as not being owned by the provided UID and will show before and \nafter listing of the file:\n\n```\nUpdating ownership permissions on workspace directory /home/devops/actions-runner-personal/_work/reset-workspace-ownership-action/reset-workspace-ownership-action\n  user: 1000\ntotal 44\ndrwxrwxr-x    5 1000     1000          4096 Nov 30 18:46 .\ndrwxr-xr-x    6 root     root          4096 Nov 30 18:46 ..\ndrwxrwxr-x    8 1000     1000          4096 Nov 30 18:46 .git\ndrwxrwxr-x    3 1000     1000          4096 Nov 30 18:46 .github\n-rw-rw-r--    1 1000     1000           102 Nov 30 18:46 Dockerfile\n-rw-rw-r--    1 1000     1000          1057 Nov 30 18:46 LICENSE.md\n-rw-rw-r--    1 1000     1000          3678 Nov 30 18:46 README.md\n-rw-rw-r--    1 1000     1000           555 Nov 30 18:46 action.yml\n-rwxrwxr-x    1 1000     1000           479 Nov 30 18:46 entrypoint.sh\ndrwxr-xr-x    3 root     root          4096 Nov 30 18:46 src\n-rwxrwxr-x    1 1000     1000           317 Nov 30 18:46 update_file_object.sh\n\nLooking for files/directories in current working directory not owned by \"1000\"\n\nUpdating ownership: ./src\n  drwxr-xr-x    3 root     root          4096 Nov 30 18:46 ./src\nchanged ownership of './src' to 1000:0\nModified ownership: ./src\n  drwxr-xr-x    3 1000     root          4096 Nov 30 18:46 ./src\n\nUpdating ownership: ./src/main\n  drwxr-xr-x    3 root     root          4096 Nov 30 18:46 ./src/main\nchanged ownership of './src/main' to 1000:0\nModified ownership: ./src/main\n  drwxr-xr-x    3 1000     root          4096 Nov 30 18:46 ./src/main\n\nUpdating ownership: ./src/main/resources\n  drwxr-xr-x    2 root     root          4096 Nov 30 18:46 ./src/main/resources\nchanged ownership of './src/main/resources' to 1000:0\nModified ownership: ./src/main/resources\n  drwxr-xr-x    2 1000     root          4096 Nov 30 18:46 ./src/main/resources\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeter-murray%2Freset-workspace-ownership-action","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeter-murray%2Freset-workspace-ownership-action","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeter-murray%2Freset-workspace-ownership-action/lists"}