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: add an output locked #135

Merged
merged 5 commits into from
Dec 16, 2024
Merged

feat: add an output locked #135

merged 5 commits into from
Dec 16, 2024

Conversation

suzuki-shunsuke
Copy link
Owner

@suzuki-shunsuke suzuki-shunsuke commented Dec 11, 2024

Add an output locked if mode is either lock or check.
This output is useful for other GitHub Actions jobs to check if the job acquires the lock.

e.g.

  lock:
    runs-on: ubuntu-latest
    permissions:
      contents: write
    outputs:
      locked: ${{steps.lock.outputs.locked}}
    steps:
      - uses: suzuki-shunsuke/lock-action@c752be910ac812e0adc50316855416514d364b57 # v0.1.3
        id: lock
        with:
          mode: lock
          key: dev
      # ...

  unlock:
    runs-on: ubuntu-latest
    needs: lock
    permissions:
      contents: write
    steps:
      - uses: suzuki-shunsuke/lock-action@c752be910ac812e0adc50316855416514d364b57 # v0.1.3
        if: needs.lock.outputs.locked == 'true'
        with:
          mode: unlock
          key: dev

@suzuki-shunsuke suzuki-shunsuke added the enhancement New feature or request label Dec 11, 2024
@suzuki-shunsuke suzuki-shunsuke added this to the v0.1.4 milestone Dec 11, 2024
src/lock.ts Outdated
@@ -14,16 +14,20 @@ export const lock = async (input: lib.Input) => {
switch (result) {
case Result.AlreadyLocked:
core.setOutput("already_locked", true);
core.setOutput("locked", true);
Copy link
Owner Author

@suzuki-shunsuke suzuki-shunsuke Dec 11, 2024

Choose a reason for hiding this comment

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

I guess this should be false.

locked should be true only if the step has acquired a lock.

@@ -20,6 +20,7 @@ export const check = async (input: lib.Input) => {
core.setOutput("result", s);
core.info(`result: ${s}`);
const alreadyLocked = metadata?.state === "lock";
core.setOutput("locked", alreadyLocked);
core.setOutput("already_locked", alreadyLocked);
Copy link
Owner Author

Choose a reason for hiding this comment

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

Honestly, I want to remove already_locked if mode is check, but it's a breaking change.

Copy link

🚀 Pre-release v0.1.4-5 was created

Build link | Release

You can try the pre-release version in your workflows by changing version to v0.1.4-5.

@suzuki-shunsuke suzuki-shunsuke merged commit 3077f23 into main Dec 16, 2024
9 checks passed
@suzuki-shunsuke suzuki-shunsuke deleted the feat-add-output-locked branch December 16, 2024 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant