Skip to content

Commit 87f1647

Browse files
committed
feat(actions): add working-directory
Signed-off-by: Emilien Escalle <[email protected]>
1 parent e4c3529 commit 87f1647

3 files changed

Lines changed: 118 additions & 20 deletions

File tree

README.md

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,37 @@ Opinionated GitHub Actions and reusable workflows for foundational continuous-in
1919

2020
### Workflow & repository automation
2121

22-
- [Checkout](actions/checkout/README.md) event-aware drop-in replacement for `actions/checkout` that supports issue comment triggers.
23-
- [Create and merge pull request](actions/create-and-merge-pull-request/README.md) opens a pull request, rebases, and merges it with the GitHub Actions bot identity.
24-
- [Create or update comment](actions/create-or-update-comment/README.md) adds or updates comments on issues and pull requests idempotently.
25-
- [Get GitHub Actions bot user](actions/get-github-actions-bot-user/README.md) retrieves the profile information for the GitHub Actions bot.
26-
- [Get issue number](actions/get-issue-number/README.md) extracts the relevant issue number from the current workflow context.
22+
- [Checkout](actions/checkout/README.md) - event-aware drop-in replacement for `actions/checkout` that supports issue comment triggers.
23+
- [Create and merge pull request](actions/create-and-merge-pull-request/README.md) - opens a pull request, rebases, and merges it with the GitHub Actions bot identity.
24+
- [Create or update comment](actions/create-or-update-comment/README.md) - adds or updates comments on issues and pull requests idempotently.
25+
- [Get GitHub Actions bot user](actions/get-github-actions-bot-user/README.md) - retrieves the profile information for the GitHub Actions bot.
26+
- [Get issue number](actions/get-issue-number/README.md) - extracts the relevant issue number from the current workflow context.
2727

2828
### Matrix & workflow data helpers
2929

30-
- [Get matrix outputs](actions/get-matrix-outputs/README.md) aggregates outputs across matrix jobs for downstream steps.
31-
- [Set matrix output](actions/set-matrix-output/README.md) writes structured outputs that can be consumed by other matrix jobs.
32-
- [Local workflow actions](actions/local-workflow-actions/README.md) loads reusable workflow actions from the current repository.
30+
- [Get matrix outputs](actions/get-matrix-outputs/README.md) - aggregates outputs across matrix jobs for downstream steps.
31+
- [Set matrix output](actions/set-matrix-output/README.md) - writes structured outputs that can be consumed by other matrix jobs.
32+
- [Local workflow actions](actions/local-workflow-actions/README.md) - loads reusable workflow actions from the current repository.
3333

3434
### Repository insights & utilities
3535

36-
- [Parse CI reports](actions/parse-ci-reports/README.md) — parses CI reports (tests, linting, coverage) into GitHub summaries and Markdown for PR comments.
37-
- [Repository owner is organization](actions/repository-owner-is-organization/README.md) — checks whether the repository owner is an organization.
38-
- [Slugify](actions/slugify/README.md) — converts free-form strings into GitHub-friendly slugs.
36+
- [Parse CI reports](actions/parse-ci-reports/README.md) - parses CI reports (tests, linting, coverage) into GitHub summaries and Markdown for PR comments.
37+
- [Repository owner is organization](actions/repository-owner-is-organization/README.md) - checks whether the repository owner is an organization.
38+
- [Working directory](actions/resolve-working-directory/README.md) - resolves and validates a working directory path as an absolute path.
39+
- [Slugify](actions/slugify/README.md) - converts free-form strings into GitHub-friendly slugs.
3940

4041
## Reusable Workflows
4142

4243
### Community & issue hygiene
4344

44-
- [Greetings](.github/workflows/greetings.md) welcomes first-time issue reporters and pull request authors.
45-
- [Need fix to Issue](.github/workflows/need-fix-to-issue.md) labels issues that require follow-up fixes.
46-
- [Stale](.github/workflows/stale.md) automatically marks and closes stale issues and pull requests.
45+
- [Greetings](.github/workflows/greetings.md) - welcomes first-time issue reporters and pull request authors.
46+
- [Need fix to Issue](.github/workflows/need-fix-to-issue.md) - labels issues that require follow-up fixes.
47+
- [Stale](.github/workflows/stale.md) - automatically marks and closes stale issues and pull requests.
4748

4849
### Quality gates
4950

50-
- [Linter](.github/workflows/linter.md) runs Super Linter and shared formatting checks across the repository.
51-
- [Semantic pull request](.github/workflows/semantic-pull-request.md) enforces semantic pull request titles before merging.
51+
- [Linter](.github/workflows/linter.md) - runs Super Linter and shared formatting checks across the repository.
52+
- [Semantic pull request](.github/workflows/semantic-pull-request.md) - enforces semantic pull request titles before merging.
5253

5354
## Contributing
5455

@@ -67,10 +68,10 @@ actions/{action-name}/
6768

6869
### Development standards
6970

70-
1. **Pinned dependencies** reference external actions by commit SHA (for example `actions/checkout@08c6903c…`).
71-
2. **Composite-first** encapsulate logic in composite actions and keep scripts minimal.
72-
3. **Early validation** validate inputs up front using GitHub Script or shell guards and fail fast with helpful messages.
73-
4. **Consistent branding** set `author: hoverkraft` and `branding.color: blue` with an appropriate icon in every `action.yml`.
71+
1. **Pinned dependencies** - reference external actions by commit SHA (for example `actions/checkout@08c6903c…`).
72+
2. **Composite-first** - encapsulate logic in composite actions and keep scripts minimal.
73+
3. **Early validation** - validate inputs up front using GitHub Script or shell guards and fail fast with helpful messages.
74+
4. **Consistent branding** - set `author: hoverkraft` and `branding.color: blue` with an appropriate icon in every `action.yml`.
7475

7576
## Development Workflow
7677

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<!-- header:start -->
2+
3+
# GitHub Action: Resolve working directory
4+
5+
<div align="center">
6+
<img src="../../.github/logo.svg" width="60px" align="center" alt="Resolve working directory" />
7+
</div>
8+
9+
---
10+
11+
<!-- header:end -->
12+
13+
## Overview
14+
15+
Action to resolve and validate a working directory path.
16+
17+
## Usage
18+
19+
```yaml
20+
- id: resolve-working-directory
21+
uses: hoverkraft-tech/ci-github-common/actions/resolve-working-directory@<sha>
22+
with:
23+
working-directory: .
24+
```
25+
26+
## Inputs
27+
28+
| **Input** | **Description** | **Required** | **Default** |
29+
| ----------------------- | ------------------------------------------------------- | ------------ | ----------- |
30+
| **`working-directory`** | Relative or absolute working directory path to resolve. | No | `.` |
31+
32+
## Outputs
33+
34+
| **Output** | **Description** |
35+
| ----------------------- | --------------------------------------------- |
36+
| **`working-directory`** | The resolved absolute working directory path. |
37+
38+
## Example
39+
40+
```yaml
41+
jobs:
42+
example:
43+
runs-on: ubuntu-latest
44+
steps:
45+
- uses: actions/checkout@v4
46+
- id: resolve-working-directory
47+
uses: hoverkraft-tech/ci-github-common/actions/resolve-working-directory@<sha>
48+
with:
49+
working-directory: actions/parse-ci-reports
50+
51+
- name: Show resolved directory
52+
run: echo "${{ steps.resolve-working-directory.outputs.working-directory }}"
53+
```
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: "working directory"
2+
description: "Action to resolve and validate a working directory path."
3+
author: hoverkraft
4+
branding:
5+
icon: folder
6+
color: blue
7+
8+
inputs:
9+
working-directory:
10+
description: "Relative or absolute working directory path to resolve."
11+
required: false
12+
default: "."
13+
14+
outputs:
15+
working-directory:
16+
description: "The resolved absolute working directory path."
17+
value: ${{ steps.working-directory.outputs.working-directory }}
18+
19+
runs:
20+
using: "composite"
21+
steps:
22+
- id: working-directory
23+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
24+
env:
25+
WORKING_DIRECTORY_INPUT: ${{ inputs.working-directory }}
26+
with:
27+
script: |
28+
const fs = require('node:fs');
29+
const path = require('node:path');
30+
31+
let workingDirectory = process.env.WORKING_DIRECTORY_INPUT || '.';
32+
33+
if (!path.isAbsolute(workingDirectory)) {
34+
workingDirectory = path.join(process.env.GITHUB_WORKSPACE, workingDirectory);
35+
}
36+
37+
if (!fs.existsSync(workingDirectory)) {
38+
core.setFailed(`The specified working directory does not exist: ${workingDirectory}`);
39+
return;
40+
}
41+
42+
workingDirectory = path.resolve(workingDirectory);
43+
core.debug(`Running in working directory: ${workingDirectory}`);
44+
core.setOutput('working-directory', workingDirectory);

0 commit comments

Comments
 (0)