{"id":15099346,"url":"https://github.com/urcomputeringpal/label-mutex","last_synced_at":"2025-06-11T09:03:42.432Z","repository":{"id":56524122,"uuid":"306053368","full_name":"urcomputeringpal/label-mutex","owner":"urcomputeringpal","description":"A GitHub Action that facilitates obtaining, releasing, and representing a lock on a shared resource using PR labels.","archived":false,"fork":false,"pushed_at":"2025-03-13T18:09:07.000Z","size":77,"stargazers_count":3,"open_issues_count":14,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-28T11:11:06.390Z","etag":null,"topics":["actions","github-actions"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/urcomputeringpal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-21T14:34:58.000Z","updated_at":"2024-05-09T01:58:24.000Z","dependencies_parsed_at":"2023-10-13T09:32:00.184Z","dependency_job_id":"249f9292-b97e-49f2-8608-1f048adfd089","html_url":"https://github.com/urcomputeringpal/label-mutex","commit_stats":{"total_commits":41,"total_committers":4,"mean_commits":10.25,"dds":0.5609756097560976,"last_synced_commit":"7869d78be279da8d2b7e6b73f89e81e8c5dde1ba"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/urcomputeringpal%2Flabel-mutex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/urcomputeringpal%2Flabel-mutex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/urcomputeringpal%2Flabel-mutex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/urcomputeringpal%2Flabel-mutex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/urcomputeringpal","download_url":"https://codeload.github.com/urcomputeringpal/label-mutex/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248787282,"owners_count":21161580,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["actions","github-actions"],"created_at":"2024-09-25T17:11:04.612Z","updated_at":"2025-04-14T23:08:59.913Z","avatar_url":"https://github.com/urcomputeringpal.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# label-mutex\n\nA GitHub Action that facilitates obtaining, releasing, and representing a lock on a shared resource using PR labels. Add a label to obtain the lock, remove it or close/merge the PR to release the lock.\n\nLet's say you'd like to allow engineers to deploy PRs to staging by adding a `staging` label to their PRs, but want to ensure that only one PR can be deployed to staging at a time. This action can be used to ensure that only one PR has a `staging` label at the same time like so:\n\n### Confirm lock when labeled\n\n```yaml\non:\n  pull_request:\n    types:\n      - opened\n      - labeled\n      - synchronize\n      - reopened\n\n      #jobs:\n      #  deploy:\n      #    steps:\n\n      - uses: urcomputeringpal/label-mutex@v0.4.0\n        id: label-mutex\n        env:\n          AWS_DEFAULT_REGION: us-east-1\n          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}\n          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}\n        with:\n          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n          label: staging\n          lock: staging\n      - name: fail-if-not-locked\n        env:\n          PR_URL: ${{ github.event.pull_request.html_url }}\n          LOCKED: ${{ steps.label-mutex.outputs.locked }}\n          LOCK_URL: ${{ steps.label-mutex.outputs.html_url }}\n        run: |\n          if [ \"$LOCKED\" == \"true\" ] \u0026\u0026 [ \"$PR_URL\" != \"$LOCK_URL\" ]; then\n            echo \"::warning ::Couldn't obtain a lock on staging. Someone may already be using it: $LOCK_URL\"\n            exit 1\n          fi\n```\n\n### Unlock on unlabel and close\n\n```yaml\non:\n  pull_request:\n    types:\n      - closed\n      - unlabeled\n\n      #jobs:\n      #  unlock:\n      #    steps:\n\n      - uses: urcomputeringpal/label-mutex@v0.4.0\n        id: label-mutex\n        env:\n          AWS_DEFAULT_REGION: us-east-1\n          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}\n          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}\n        with:\n          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n          label: staging\n          lock: staging\n```\n\n## Setup\n\n### AWS\n\n#### Lock table\n\n```hcl\nresource \"aws_dynamodb_table\" \"label_mutex\" {\n  name         = \"label-mutex\"\n  billing_mode = \"PAY_PER_REQUEST\"\n  hash_key     = \"name\"\n  range_key    = \"id\"\n\n  attribute {\n    name = \"id\"\n    type = \"S\"\n  }\n\n  attribute {\n    name = \"name\"\n    type = \"S\"\n  }\n\n  ttl {\n    attribute_name = \"expires\"\n    enabled        = true\n  }\n}\n```\n\n#### IAM\n\nEnsure your AWS user has the following permissions on the above table:\n\n```\ndynamodb:GetItem\ndynamodb:PutItem\ndynamodb:DeleteItem\ndynamodb:UpdateItem\n```\n\n## GCS\n\n- Setup a new project at the [Google APIs Console](https://console.developers.google.com/) and enable the Cloud Storage API.\n- Install the [Google Cloud SDK tool](https://cloud.google.com/sdk/downloads) and configure your project and your OAuth credentials.\n- Run the following command to setup a bucket and OIDC config for GitHub Actions in your current project:\n\n```bash\n PROJECT_ID=$(gcloud config get-value project) \\\n PROJECT_NUMBER=$(gcloud projects describe $PROJECT_ID --format='value(projectNumber)') \\\n REPONAME=$(basename $(git rev-parse --show-toplevel)) \\\n hack/gcloud-setup.sh\n```\n\nUse the YAML output by that script, or refer to this example:\n\n```yaml\n# Example workflow\njobs:\n  gcloud-authenticated-job:\n    runs-on: ubuntu-latest\n    permissions:\n      contents: read\n      id-token: write\n      pull-requests: write\n    steps:\n      - uses: actions/checkout@v4\n      - id: auth\n        name: Authenticate to Google Cloud\n        uses: google-github-actions/auth@v1\n        with:\n          workload_identity_provider: projects/${{ env.PROJECT_NUMBER }}/locations/${{ env.LOCATION }}/workloadIdentityPools/${{ env.POOL_NAME }}/providers/${{ env.PROVIDER_NAME }}\n          service_account: ${ env.SERVICE_ACCOUNT }}\n          create_credentials_file: true\n          export_environment_variables: true\n          access_token_scopes: https://www.googleapis.com/auth/devstorage.full_control\n      - uses: docker://ghcr.io/urcomputeringpal/label-mutex:v0.4.0\n        id: label-mutex\n        with:\n          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n          bucket: ${{ env.BUCKET }}\n          lock: example-lock\n          label: example-lock\n          lock: staging\n      - name: fail-if-not-locked\n        env:\n          PR_URL: ${{ github.event.pull_request.html_url }}\n          LOCKED: ${{ steps.label-mutex.outputs.locked }}\n          LOCK_URL: ${{ steps.label-mutex.outputs.html_url }}\n        run: |\n          if [ \"$LOCKED\" == \"true\" ] \u0026\u0026 [ \"$PR_URL\" != \"$LOCK_URL\" ]; then\n            echo \"::warning ::Couldn't obtain a lock on staging. Someone may already be using it: $LOCK_URL\"\n            exit 1\n          fi\n```\n\n## Acknowledgements\n\n- https://github.com/sethvargo/go-hello-githubactions\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Furcomputeringpal%2Flabel-mutex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Furcomputeringpal%2Flabel-mutex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Furcomputeringpal%2Flabel-mutex/lists"}