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

feat(config): support reading from local file if it exists #394

Merged
merged 9 commits into from
Jul 7, 2023
Merged

feat(config): support reading from local file if it exists #394

merged 9 commits into from
Jul 7, 2023

Conversation

lrstanley
Copy link
Contributor

Currently, actions/labeler can only read the configuration from the source repository, due to it using the context and API to fetch the configuration file. This PR adds support for first checking to see if a file matching the provided path exists locally, before it makes a call to the API to get the file.

The primary benefit for this, is it works well with reusable workflows, as all you have to do is grab the file from a central location, before running this on the target repository.

@lrstanley lrstanley requested a review from a team as a code owner June 25, 2022 22:27
@mac2000
Copy link

mac2000 commented Mar 12, 2023

This change will also fix #16

comment with back link

@lrstanley lrstanley requested a review from a team as a code owner March 14, 2023 01:58
@javiergonzalezGenially
Copy link

Any news about this? This is actually needed when labeler.yml is auto-generated in build time.

@simbo
Copy link

simbo commented May 30, 2023

@lrstanley I created a PR for your PR, that updates the branch and uses async readFile.
https://github.com/lrstanley/labeler/pull/1

Copy link
Contributor

@AndreiLobanovich AndreiLobanovich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, @lrstanley!
Thanks for your contribution!
I left a few comments, otherwise your solution looks great.

src/labeler.ts Outdated Show resolved Hide resolved
src/labeler.ts Outdated Show resolved Hide resolved
src/labeler.ts Outdated Show resolved Hide resolved
src/labeler.ts Outdated Show resolved Hide resolved
Signed-off-by: Liam Stanley <me@liamstanley.io>
Copy link
Contributor

@AndreiLobanovich AndreiLobanovich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, @lrstanley! Thanks for your changes. Could you also provide us with the test case for this functionality?

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@AndreiLobanovich
Copy link
Contributor

Hey, @lrstanley!
Do you have some spare time to finish this PR? Is there anything I can help you with?

@lrstanley
Copy link
Contributor Author

Hey, @lrstanley! Thanks for your changes. Could you also provide us with the test case for this functionality?

I don't see any existing mock/testing functionality for the actual reads from the API, and if I write a test, it should probably cover the case if a file doesn't exist (or similar), which means it'd try and read from the remote. Not sure best practice on how to implement that. Do the octokit libraries provide ways of mocking those calls?

src/labeler.ts Outdated Show resolved Hide resolved
@AndreiLobanovich
Copy link
Contributor

@lrstanley as for tests - you may utilize the following approach.

src/labeler.ts Outdated Show resolved Hide resolved
@MaksimZhukov
Copy link
Contributor

I don't see any existing mock/testing functionality for the actual reads from the API, and if I write a test, it should probably cover the case if a file doesn't exist (or similar), which means it'd try and read from the remote. Not sure best practice on how to implement that. Do the octokit libraries provide ways of mocking those calls?

I think we can add two tests here:

  1. uses local configuration file if it exists
  2. fetches the content of configuration file via API if not found locally

Here is an example of the first test case:

  it('uses local configuration file if it exists', async () => {
    const configFile = 'only_pdfs.yml';
    const configFilePath = path.join(__dirname, 'fixtures', configFile);
    
    configureInput({
      'configuration-path': configFilePath
    });

    await run();

    expect(reposMock).toHaveBeenCalledTimes(0);
  });

@MaksimZhukov MaksimZhukov merged commit 994304c into actions:main Jul 7, 2023
@MaksimZhukov
Copy link
Contributor

@lrstanley thank you for the contribution!

github-merge-queue bot referenced this pull request in owntracks/android Jul 11, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [actions/labeler](https://togithub.com/actions/labeler) | action |
minor | `v4.2.0` -> `v4.3.0` |

---

### ⚠ Dependency Lookup Warnings ⚠

Warnings were logged while processing this repo. Please check the logs
for more information.

---

### Release Notes

<details>
<summary>actions/labeler (actions/labeler)</summary>

### [`v4.3.0`](https://togithub.com/actions/labeler/releases/tag/v4.3.0)

[Compare
Source](https://togithub.com/actions/labeler/compare/v4.2.0...v4.3.0)

#### What's Changed

In scope of this release, the ability to specify pull request number(s)
was added by [@&#8203;credfeto](https://togithub.com/credfeto) in
[https://github.com/actions/labeler/pull/349](https://togithub.com/actions/labeler/pull/349).

Support for reading from the configuration file presented on the runner
was added by [@&#8203;lrstanley](https://togithub.com/lrstanley) in
[https://github.com/actions/labeler/pull/394](https://togithub.com/actions/labeler/pull/394).
It allows you to use a configuration file generated during workflow run
or uploaded from a separate repository.

Please refer to the [action
documentation](https://togithub.com/actions/labeler#inputs) for more
information.

This release also includes the following changes:

- Improved Error message for missing config file by
[@&#8203;Gornoka](https://togithub.com/Gornoka) in
[https://github.com/actions/labeler/pull/475](https://togithub.com/actions/labeler/pull/475)
- Early exit when no files are changed by
[@&#8203;nathanhammond](https://togithub.com/nathanhammond) in
[https://github.com/actions/labeler/pull/456](https://togithub.com/actions/labeler/pull/456)
- Add examples to match all repo files by
[@&#8203;MaksimZhukov](https://togithub.com/MaksimZhukov) in
[https://github.com/actions/labeler/pull/600](https://togithub.com/actions/labeler/pull/600)
- Fix a typo in the example about using the action outputs by
[@&#8203;MaksimZhukov](https://togithub.com/MaksimZhukov) in
[https://github.com/actions/labeler/pull/606](https://togithub.com/actions/labeler/pull/606)
- Bump eslint from 8.43.0 to 8.44.0 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[https://github.com/actions/labeler/pull/601](https://togithub.com/actions/labeler/pull/601)
- Bump
[@&#8203;typescript-eslint/parser](https://togithub.com/typescript-eslint/parser)
from 5.60.1 to 5.61.0 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[https://github.com/actions/labeler/pull/602](https://togithub.com/actions/labeler/pull/602)
- Bump
[@&#8203;typescript-eslint/eslint-plugin](https://togithub.com/typescript-eslint/eslint-plugin)
from 5.60.1 to 5.61.0 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[https://github.com/actions/labeler/pull/604](https://togithub.com/actions/labeler/pull/604)
- Bump tough-cookie from 4.1.2 to 4.1.3 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[https://github.com/actions/labeler/pull/609](https://togithub.com/actions/labeler/pull/609)
- Bump
[@&#8203;octokit/plugin-retry](https://togithub.com/octokit/plugin-retry)
from 5.0.4 to 5.0.5 by
[@&#8203;MaksimZhukov](https://togithub.com/MaksimZhukov) in
[https://github.com/actions/labeler/pull/610](https://togithub.com/actions/labeler/pull/610)

#### New Contributors

- [@&#8203;credfeto](https://togithub.com/credfeto) made their first
contribution in
[https://github.com/actions/labeler/pull/349](https://togithub.com/actions/labeler/pull/349)
- [@&#8203;lrstanley](https://togithub.com/lrstanley) made their first
contribution in
[https://github.com/actions/labeler/pull/394](https://togithub.com/actions/labeler/pull/394)
- [@&#8203;nathanhammond](https://togithub.com/nathanhammond) made their
first contribution in
[https://github.com/actions/labeler/pull/456](https://togithub.com/actions/labeler/pull/456)

**Full Changelog**:
actions/labeler@v4...v4.3.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/owntracks/android).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi41LjMiLCJ1cGRhdGVkSW5WZXIiOiIzNi41LjMiLCJ0YXJnZXRCcmFuY2giOiJtYXN0ZXIifQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
github-merge-queue bot referenced this pull request in owntracks/android Jul 11, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [actions/labeler](https://togithub.com/actions/labeler) | action |
minor | `v4.2.0` -> `v4.3.0` |

---

### ⚠ Dependency Lookup Warnings ⚠

Warnings were logged while processing this repo. Please check the logs
for more information.

---

### Release Notes

<details>
<summary>actions/labeler (actions/labeler)</summary>

### [`v4.3.0`](https://togithub.com/actions/labeler/releases/tag/v4.3.0)

[Compare
Source](https://togithub.com/actions/labeler/compare/v4.2.0...v4.3.0)

#### What's Changed

In scope of this release, the ability to specify pull request number(s)
was added by [@&#8203;credfeto](https://togithub.com/credfeto) in
[https://github.com/actions/labeler/pull/349](https://togithub.com/actions/labeler/pull/349).

Support for reading from the configuration file presented on the runner
was added by [@&#8203;lrstanley](https://togithub.com/lrstanley) in
[https://github.com/actions/labeler/pull/394](https://togithub.com/actions/labeler/pull/394).
It allows you to use a configuration file generated during workflow run
or uploaded from a separate repository.

Please refer to the [action
documentation](https://togithub.com/actions/labeler#inputs) for more
information.

This release also includes the following changes:

- Improved Error message for missing config file by
[@&#8203;Gornoka](https://togithub.com/Gornoka) in
[https://github.com/actions/labeler/pull/475](https://togithub.com/actions/labeler/pull/475)
- Early exit when no files are changed by
[@&#8203;nathanhammond](https://togithub.com/nathanhammond) in
[https://github.com/actions/labeler/pull/456](https://togithub.com/actions/labeler/pull/456)
- Add examples to match all repo files by
[@&#8203;MaksimZhukov](https://togithub.com/MaksimZhukov) in
[https://github.com/actions/labeler/pull/600](https://togithub.com/actions/labeler/pull/600)
- Fix a typo in the example about using the action outputs by
[@&#8203;MaksimZhukov](https://togithub.com/MaksimZhukov) in
[https://github.com/actions/labeler/pull/606](https://togithub.com/actions/labeler/pull/606)
- Bump eslint from 8.43.0 to 8.44.0 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[https://github.com/actions/labeler/pull/601](https://togithub.com/actions/labeler/pull/601)
- Bump
[@&#8203;typescript-eslint/parser](https://togithub.com/typescript-eslint/parser)
from 5.60.1 to 5.61.0 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[https://github.com/actions/labeler/pull/602](https://togithub.com/actions/labeler/pull/602)
- Bump
[@&#8203;typescript-eslint/eslint-plugin](https://togithub.com/typescript-eslint/eslint-plugin)
from 5.60.1 to 5.61.0 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[https://github.com/actions/labeler/pull/604](https://togithub.com/actions/labeler/pull/604)
- Bump tough-cookie from 4.1.2 to 4.1.3 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[https://github.com/actions/labeler/pull/609](https://togithub.com/actions/labeler/pull/609)
- Bump
[@&#8203;octokit/plugin-retry](https://togithub.com/octokit/plugin-retry)
from 5.0.4 to 5.0.5 by
[@&#8203;MaksimZhukov](https://togithub.com/MaksimZhukov) in
[https://github.com/actions/labeler/pull/610](https://togithub.com/actions/labeler/pull/610)

#### New Contributors

- [@&#8203;credfeto](https://togithub.com/credfeto) made their first
contribution in
[https://github.com/actions/labeler/pull/349](https://togithub.com/actions/labeler/pull/349)
- [@&#8203;lrstanley](https://togithub.com/lrstanley) made their first
contribution in
[https://github.com/actions/labeler/pull/394](https://togithub.com/actions/labeler/pull/394)
- [@&#8203;nathanhammond](https://togithub.com/nathanhammond) made their
first contribution in
[https://github.com/actions/labeler/pull/456](https://togithub.com/actions/labeler/pull/456)

**Full Changelog**:
actions/labeler@v4...v4.3.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/owntracks/android).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi41LjMiLCJ1cGRhdGVkSW5WZXIiOiIzNi41LjMiLCJ0YXJnZXRCcmFuY2giOiJtYXN0ZXIifQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
flookapa referenced this pull request in flookapa/owntracks_android Aug 27, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [actions/labeler](https://togithub.com/actions/labeler) | action |
minor | `v4.2.0` -> `v4.3.0` |

---

### ⚠ Dependency Lookup Warnings ⚠

Warnings were logged while processing this repo. Please check the logs
for more information.

---

### Release Notes

<details>
<summary>actions/labeler (actions/labeler)</summary>

### [`v4.3.0`](https://togithub.com/actions/labeler/releases/tag/v4.3.0)

[Compare
Source](https://togithub.com/actions/labeler/compare/v4.2.0...v4.3.0)

#### What's Changed

In scope of this release, the ability to specify pull request number(s)
was added by [@&#8203;credfeto](https://togithub.com/credfeto) in
[https://github.com/actions/labeler/pull/349](https://togithub.com/actions/labeler/pull/349).

Support for reading from the configuration file presented on the runner
was added by [@&#8203;lrstanley](https://togithub.com/lrstanley) in
[https://github.com/actions/labeler/pull/394](https://togithub.com/actions/labeler/pull/394).
It allows you to use a configuration file generated during workflow run
or uploaded from a separate repository.

Please refer to the [action
documentation](https://togithub.com/actions/labeler#inputs) for more
information.

This release also includes the following changes:

- Improved Error message for missing config file by
[@&#8203;Gornoka](https://togithub.com/Gornoka) in
[https://github.com/actions/labeler/pull/475](https://togithub.com/actions/labeler/pull/475)
- Early exit when no files are changed by
[@&#8203;nathanhammond](https://togithub.com/nathanhammond) in
[https://github.com/actions/labeler/pull/456](https://togithub.com/actions/labeler/pull/456)
- Add examples to match all repo files by
[@&#8203;MaksimZhukov](https://togithub.com/MaksimZhukov) in
[https://github.com/actions/labeler/pull/600](https://togithub.com/actions/labeler/pull/600)
- Fix a typo in the example about using the action outputs by
[@&#8203;MaksimZhukov](https://togithub.com/MaksimZhukov) in
[https://github.com/actions/labeler/pull/606](https://togithub.com/actions/labeler/pull/606)
- Bump eslint from 8.43.0 to 8.44.0 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[https://github.com/actions/labeler/pull/601](https://togithub.com/actions/labeler/pull/601)
- Bump
[@&#8203;typescript-eslint/parser](https://togithub.com/typescript-eslint/parser)
from 5.60.1 to 5.61.0 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[https://github.com/actions/labeler/pull/602](https://togithub.com/actions/labeler/pull/602)
- Bump
[@&#8203;typescript-eslint/eslint-plugin](https://togithub.com/typescript-eslint/eslint-plugin)
from 5.60.1 to 5.61.0 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[https://github.com/actions/labeler/pull/604](https://togithub.com/actions/labeler/pull/604)
- Bump tough-cookie from 4.1.2 to 4.1.3 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[https://github.com/actions/labeler/pull/609](https://togithub.com/actions/labeler/pull/609)
- Bump
[@&#8203;octokit/plugin-retry](https://togithub.com/octokit/plugin-retry)
from 5.0.4 to 5.0.5 by
[@&#8203;MaksimZhukov](https://togithub.com/MaksimZhukov) in
[https://github.com/actions/labeler/pull/610](https://togithub.com/actions/labeler/pull/610)

#### New Contributors

- [@&#8203;credfeto](https://togithub.com/credfeto) made their first
contribution in
[https://github.com/actions/labeler/pull/349](https://togithub.com/actions/labeler/pull/349)
- [@&#8203;lrstanley](https://togithub.com/lrstanley) made their first
contribution in
[https://github.com/actions/labeler/pull/394](https://togithub.com/actions/labeler/pull/394)
- [@&#8203;nathanhammond](https://togithub.com/nathanhammond) made their
first contribution in
[https://github.com/actions/labeler/pull/456](https://togithub.com/actions/labeler/pull/456)

**Full Changelog**:
actions/labeler@v4...v4.3.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/owntracks/android).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi41LjMiLCJ1cGRhdGVkSW5WZXIiOiIzNi41LjMiLCJ0YXJnZXRCcmFuY2giOiJtYXN0ZXIifQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Issue when share workflow within organization
8 participants