diff --git a/.env b/.env index e0df92c..021c269 100644 --- a/.env +++ b/.env @@ -1,6 +1,6 @@ GITHUB_EVENT_NAME=push GITHUB_EVENT_PATH=test/fixtures/payload.json -GITHUB_REPOSITORY=ahmadnassri/action-workflow-queue +GITHUB_REPOSITORY=durable-code/workflow-queue GITHUB_WORKSPACE=/github/workspace INPUT_GITHUB-TOKEN=$GITHUB_TOKEN diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml deleted file mode 100644 index c244427..0000000 --- a/.github/FUNDING.yml +++ /dev/null @@ -1,5 +0,0 @@ -# ----------------------------------------------- # -# Note: this file originates in template-template # -# ----------------------------------------------- # - -github: [ahmadnassri] diff --git a/.github/workflows/pull_request_target.yml b/.github/workflows/pull_request_target.yml deleted file mode 100644 index 3bc886c..0000000 --- a/.github/workflows/pull_request_target.yml +++ /dev/null @@ -1,14 +0,0 @@ -# ----------------------------------------------- # -# Note: this file originates in template-template # -# ----------------------------------------------- # - -name: pull_request_target - -on: pull_request_target - -permissions: read-all - -jobs: - main: - uses: ahmadnassri/actions/.github/workflows/pull-request-target.yml@master - secrets: inherit diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml deleted file mode 100644 index 245ec52..0000000 --- a/.github/workflows/push.yml +++ /dev/null @@ -1,21 +0,0 @@ -# ---------------------------------------------------- # -# Note: this file originates in template-action-docker # -# ---------------------------------------------------- # - -name: push - -on: - - push - - workflow_dispatch - -permissions: read-all - -jobs: - main: - uses: ahmadnassri/actions/.github/workflows/push-action-docker.yml@master - secrets: inherit - permissions: - contents: write - statuses: write - packages: write - pull-requests: write diff --git a/Dockerfile b/Dockerfile index f71229b..7c27464 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,12 +4,12 @@ FROM alpine:3.19 AS base # hadolint ignore=DL3018 RUN apk add --no-cache --update \ - nodejs=18.18.2-r0 \ - git=2.40.1-r0 \ - openssh=9.3_p2-r0 \ - ca-certificates=20230506-r0 \ + nodejs=20.11.1-r0 \ + git=2.43.0-r0 \ + openssh=9.6_p1-r0 \ + ca-certificates=20240226-r0 \ ruby-bundler=2.4.15-r0 \ - bash=5.2.15-r5 + bash=5.2.21-r0 WORKDIR /action @@ -18,7 +18,7 @@ WORKDIR /action FROM base AS build # hadolint ignore=DL3018 -RUN apk add --no-cache npm=9.6.6-r0 +RUN apk add --no-cache npm=10.2.5-r0 # slience npm # hadolint ignore=DL3059 diff --git a/README.md b/README.md index 260f677..b841b2c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # GitHub Action: Workflow Run Queue -If the same workflow is already running from a previous commit, wait for it to finish +if a given workflow is already running, that this action isn't running as a part of, then wait for it to finish [![license][license-img]][license-url] [![release][release-img]][release-url] @@ -20,27 +20,37 @@ Workflows run on every commit asynchronously, this is fine for most cases, howev ###### `.github/workflows/my-workflow.yml` -``` yaml +```yaml jobs: xyz: runs-on: ubuntu-latest + permissions: + actions: read + steps: - uses: actions/checkout@v2 - - uses: ahmadnassri/action-workflow-queue@v1 + - uses: durable-code/workflow-queue + with: + run-id: ${{ github.run_id }} # only runs additional steps if there is no other instance of `my-workflow.yml` currently running ``` ### Inputs -| input | required | default | description | -|----------------|----------|----------------|-------------------------------------------------| -| `github-token` | ❌ | `github.token` | The GitHub token used to call the GitHub API | -| `timeout` | ❌ | `600000` | timeout before we stop trying (in milliseconds) | -| `delay` | ❌ | `10000` | delay between status checks (in milliseconds) | +| input | required | default | description | +| -------------- | -------- | -------------- | ------------------------------------------------------- | +| `github-token` | ❌ | `github.token` | The GitHub token used to call the GitHub API | +| `run-id` | ✅ | - | The `${{ github.run_id }}` of the caller workflow | +| `timeout` | ❌ | `600000` | timeout before we stop trying (in milliseconds) | +| `delay` | ❌ | `10000` | delay between status checks (in milliseconds) | + ---- + +Adapted from https://github.com/ahmadnassri/action-workflow-queue + > Author: [Ahmad Nassri](https://www.ahmadnassri.com/) • > Twitter: [@AhmadNassri](https://twitter.com/AhmadNassri) diff --git a/action.yml b/action.yml index d146afe..ee02aab 100644 --- a/action.yml +++ b/action.yml @@ -1,15 +1,20 @@ name: Workflow Queue -description: If the same workflow is already running from a previous commit, wait for it to finish +description: if a given workflow is already running, that this action isn't running as a part of, then wait for it to finish + branding: - color: yellow + color: green icon: clock inputs: github-token: - description: The GitHub token used to post comments on pull requests + description: The GitHub token used to check running workflows. default: ${{ github.token }} + run-id: + description: The run id of the caller workflow that this action is within. + required: true + timeout: description: timeout before we stop trying (in milliseconds) default: "600000" @@ -20,4 +25,4 @@ inputs: runs: using: docker - image: docker://ghcr.io/ahmadnassri/action-workflow-queue:1.2.0 + image: docker://ghcr.io/durable-code/workflow-queue:latest diff --git a/colophon.yml b/colophon.yml deleted file mode 100644 index 1eaed1f..0000000 --- a/colophon.yml +++ /dev/null @@ -1,8 +0,0 @@ -version: 2.0 - -id: action-workflow-queue - -about: - title: "GitHub Action: Workflow Run Queue" - description: If the same workflow is already running from a previous commit, wait for it to finish - repository: ahmadnassri/action-workflow-queue diff --git a/docs/README.md b/docs/README.md deleted file mode 100644 index 42d7dca..0000000 --- a/docs/README.md +++ /dev/null @@ -1,34 +0,0 @@ - -
- Why? - - Workflows run on every commit asynchronously, this is fine for most cases, however, you might want to wait for a previous commit workflow to finish before running another one, some example use-cases: - - - Deployment workflows - - Terraform workflows - - Database Migrations -
- -## Usage - -###### `.github/workflows/my-workflow.yml` - -```yaml -jobs: - xyz: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - uses: ahmadnassri/action-workflow-queue@v1 - - # only runs additional steps if there is no other instance of `my-workflow.yml` currently running -``` - -### Inputs - -| input | required | default | description | -| -------------- | -------- | -------------- | ----------------------------------------------- | -| `github-token` | ❌ | `github.token` | The GitHub token used to call the GitHub API | -| `timeout` | ❌ | `600000` | timeout before we stop trying (in milliseconds) | -| `delay` | ❌ | `10000` | delay between status checks (in milliseconds) | diff --git a/docs/README.template b/docs/README.template deleted file mode 100644 index fed76c1..0000000 --- a/docs/README.template +++ /dev/null @@ -1,18 +0,0 @@ -# $about.title$ - -$about.description$ - -[![license][license-img]][license-url] -[![release][release-img]][release-url] - -$body$ - ----- -> Author: [Ahmad Nassri](https://www.ahmadnassri.com/) • -> Twitter: [@AhmadNassri](https://twitter.com/AhmadNassri) - -[license-url]: LICENSE -[license-img]: https://badgen.net/github/license/$about.repository$ - -[release-url]: https://github.com/$about.repository$/releases -[release-img]: https://badgen.net/github/release/$about.repository$ diff --git a/package.json b/package.json index f4064d6..3d13410 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,11 @@ { "private": true, - "name": "actions-workflow-queue", - "version": "0.0.0-semantically-released", - "description": "wait for all `workflow_run` required workflows to be successful", + "name": "workflow-queue", + "version": "1.4.0", + "description": "if a given workflow is already running, that this action isn't running as a part of, then wait for it to finish", "author": { - "name": "Ahmad Nassri", - "email": "ahmad@ahmadnassri.com", - "url": "https://ahmadnassri.com" + "name": "Liam McInroy", + "email": "liam@durable.ai" }, "scripts": { "test": "echo nothing to test && exit 0", diff --git a/src/index.js b/src/index.js index 8a0eecc..079a702 100644 --- a/src/index.js +++ b/src/index.js @@ -10,6 +10,7 @@ import main from './lib/index.js' // parse inputs const inputs = { token: core.getInput('github-token', { required: true }), + run_id: core.getInput('run-id', { required: true }), delay: Number(core.getInput('delay', { required: true })), timeout: Number(core.getInput('timeout', { required: true })) } diff --git a/src/lib/index.js b/src/lib/index.js index e1ec4af..c12dd2d 100644 --- a/src/lib/index.js +++ b/src/lib/index.js @@ -10,15 +10,12 @@ import runs from './runs.js' // sleep function const sleep = ms => new Promise(resolve => setTimeout(resolve, ms)) -export default async function ({ token, delay, timeout }) { +export default async function ({ token, run_id, delay, timeout }) { let timer = 0 // init octokit const octokit = github.getOctokit(token) - // extract runId - const { runId: run_id } = github.context - // get workflow id and created date from run id const { data: { workflow_id, run_started_at } } = await octokit.request('GET /repos/{owner}/{repo}/actions/runs/{run_id}', { ...github.context.repo, @@ -53,7 +50,7 @@ export default async function ({ token, delay, timeout }) { } // zzz - core.info(`waiting for #${delay/1000} minutes before polling the status again`) + core.info(`waiting for #${delay/1000} seconds before polling the status again`) await sleep(delay) // get the data again diff --git a/src/lib/runs.js b/src/lib/runs.js index 6afc84a..fd71756 100644 --- a/src/lib/runs.js +++ b/src/lib/runs.js @@ -7,7 +7,7 @@ import { inspect } from 'util' import core from '@actions/core' import github from '@actions/github' -export default async function ({ octokit, workflow_id, run_id, before }) { +export default async function ({ octokit, run_id, workflow_id, before }) { // get current run of this workflow const { data: { workflow_runs } } = await octokit.request('GET /repos/{owner}/{repo}/actions/workflows/{workflow_id}/runs', { ...github.context.repo,