Skip to content

Commit 47b204a

Browse files
authored
Merge pull request #89 from guitarrapc/patch-1
Update README.md
2 parents 62af7cf + 1890d18 commit 47b204a

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

README.md

+31
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
[![build-test](https://github.com/DeNA/setup-job-workspace-action/actions/workflows/test.yml/badge.svg)](https://github.com/DeNA/setup-job-workspace-action/actions/workflows/test.yml)
33

44
# setup-job-workspace-action
5+
56
An action creating a virtual workspace directory for each job. It is useful when using self-hosted runner with large size of repository.
67

78
## Usage
9+
810
```yaml
911
jobs:
1012
default:
@@ -62,11 +64,37 @@ jobs:
6264
# ... your build steps
6365
```
6466

67+
### Example
68+
69+
Below is [Unity](https://unity.com/) build example. Unity build takes a long time if missing Library, so we want to keep it between jobs. This action can solve this problem by creating a virtual workspace directory per runner & workflow basis.
70+
71+
```yaml
72+
jobs:
73+
unity:
74+
runs-on: [self-hosted]
75+
steps:
76+
- name: Switch workspace
77+
uses: DeNA/setup-job-workspace-action@v2
78+
with:
79+
# Change path by build option
80+
suffix: "${{ (inputs.enable_XXX && '-XXX') || '' }}"
81+
- uses: actions/checkout@v3
82+
with:
83+
# Clean everything by build option
84+
clean: ${{ inputs.clean || false }}
85+
- name: Git clean without Library
86+
run: git clean -xffd --exclude Library
87+
# ... your build steps
88+
```
89+
6590
### Options
91+
6692
See [action.yml](./action.yml)
6793

6894
## Notice
95+
6996
### Default workspace name is different for older runner version.
97+
7098
`workspace-name` default is `${workflow-yaml-name}-${job-name}`, but when self-hosted runner version is older than [actions/[email protected]](https://github.com/actions/runner/releases/tag/v2.300.0) defalut is `${workflow-name}-${job-name}`.
7199

72100
This defference comes from technical reason that how to get workflow yaml name. First, try to get yaml name from `GITHUB_WORKFLOW_REF` environment variable that exposed from runner version v2.300.0
@@ -75,6 +103,7 @@ This defference comes from technical reason that how to get workflow yaml name.
75103
If you want to keep the same workspace name between different versions of the runner or for future version upgrades, specify the `workspace-name` option explicitly.
76104

77105
## How it works
106+
78107
GitHub Actions runner only has one workspace directory per repository ($GITHUB_WORKSPACE). That path is defined by the repository name, for example the workspace path of this repository is `/home/runner/work/setup-job-workspace-action/setup-job-workspace-action` in GitHub hosted Ubuntu runner.
79108

80109
This action creates a new virtual workspace directory and replaces $GITHUB_WORKSPACE as symlink that target to it. So GitHub Actions runner treats the new virtual workspace as a job workspace, it is possible to separate workspace for each job like Jenkins by creating a virtual workspace per job.
@@ -98,6 +127,7 @@ mv ${GITHUB_WORKSPACE}.bak ${GITHUB_WORKSPACE}
98127
```
99128

100129
## Why need it
130+
101131
When using GitHub-hosted runner, a new VM is given for each job. On the other hand, self-hosted runner runs on the same machine, a single workspace($GITHUB_WORKSPACE) is used for jobs that in the same repository. `actions/checkout` cleans workspace before checkout using `git clean -ffdx` in default, it works fine for a normal sized repository.
102132

103133
However, there are some problems when repository size is too large. Some of the workflows will download large binary tools for a current build and output large build cache for the next build, so `actions/checkout` default cleaning is inefficient sometimes.
@@ -107,6 +137,7 @@ And also some git options like `sparse checkout` are very efficient if your job
107137
This problem can be solved if each job has its own workspace and can reuse `.git/` created by advanced git options. Jenkins has been successful in this way for a long time. `setup-job-workspace-action` also realizes it on GitHub Actions.
108138

109139
## Development
140+
110141
```bash
111142
npm run build
112143
npm run lint

0 commit comments

Comments
 (0)