Skip to content

Commit ffe2de4

Browse files
committed
feat(local-workflow-actions): add cloned actions to ignore files
Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
1 parent a36ef22 commit ffe2de4

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

actions/local-workflow-actions/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Example: if `local-path` is `./self-workflow` and `actions-path` is `.github/act
7373
| **`local-path`** | Path inside the current workspace where to copy the local actions from the reusable workflow repository. | **false** | `./self-workflow` |
7474
| **`repository`** | The reusable workflow repository that triggered the current run, in the format `owner/repo`. | **false** | - |
7575
| | If not provided, this is automatically filled by the OIDC action. | | |
76-
| **`ref`** | The git ref (branch, tag, or SHA) of the reusable workflow repository that triggered the current run. | **false** | - |
76+
| **`ref`** | The Git ref (branch, tag, or SHA) of the reusable workflow repository that triggered the current run. | **false** | - |
7777
| | If not provided, this is automatically filled by the OIDC action. | | |
7878

7979
<!-- inputs:end -->
@@ -88,7 +88,7 @@ Example: if `local-path` is `./self-workflow` and `actions-path` is `.github/act
8888
| **Output** | **Description** |
8989
| ---------------- | ------------------------------------------------------------------------------------------- |
9090
| **`repository`** | The reusable workflow repository that was checked out, in the format `owner/repo`. |
91-
| **`ref`** | The git ref (branch, tag, or SHA) of the reusable workflow repository that was checked out. |
91+
| **`ref`** | The Git ref (branch, tag, or SHA) of the reusable workflow repository that was checked out. |
9292

9393
<!-- outputs:end -->
9494

actions/local-workflow-actions/action.yml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ description: |
33
This action checks out the reusable workflow repository that triggered the current run and copies its local actions directory into the current workspace.
44
It runs both during the main step and in the post step so that actions with cleanup hooks are also available.
55
Use it when consuming reusable workflows that reference local actions from the same repository—they are not automatically available in the caller repository and must be synced manually.
6+
Add the `self-workflow` directory to your `.gitignore` and `.dockerignore` files to avoid committing it by mistake.
67
78
Local actions will be available at `./<local-path>/<actions-path>` inside the current workspace.
89
Example: if `local-path` is `./self-workflow` and `actions-path` is `.github/actions`, then local actions will be available at `./self-workflow/.github/actions`.
@@ -48,7 +49,7 @@ runs:
4849
steps:
4950
# FIXME: This is a workaround for having workflow actions. See https://github.com/orgs/community/discussions/38659
5051
- id: oidc
51-
if: ${{ inputs.repository == '' }}
52+
if: inputs.repository == ''
5253
uses: ChristopherHX/oidc@73eee1ff03fdfce10eda179f617131532209edbd # v3
5354

5455
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
@@ -59,3 +60,26 @@ runs:
5960
ref: ${{ inputs.ref || steps.oidc.outputs.job_workflow_repo_ref }}
6061
sparse-checkout: |
6162
${{ inputs.actions-path }}
63+
64+
- uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
65+
with:
66+
script: |
67+
const fs = require('fs');
68+
const path = require('path');
69+
const entry = 'self-workflow';
70+
const ensureIgnore = (fileName) => {
71+
const filePath = path.join(process.cwd(), fileName);
72+
if (fs.existsSync(filePath)) {
73+
const content = fs.readFileSync(filePath, 'utf8');
74+
const lines = content.split(/\r?\n/);
75+
if (lines.some((line) => line.trim() === entry)) {
76+
return;
77+
}
78+
const suffix = content.endsWith('\n') ? '' : '\n';
79+
fs.writeFileSync(filePath, `${content}${suffix}${entry}\n`);
80+
} else {
81+
fs.writeFileSync(filePath, `${entry}\n`);
82+
}
83+
};
84+
85+
['.gitignore', '.dockerignore'].forEach(ensureIgnore);

0 commit comments

Comments
 (0)