Skip to content

Commit

Permalink
Wait for head SHA on pull request (#24)
Browse files Browse the repository at this point in the history
* Wait for head SHA on pull request

* Remove new line
  • Loading branch information
int128 committed Oct 13, 2022
1 parent 9f8b4e2 commit ef59f10
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,13 @@ This actions depends on `docker pull` and `docker image inspect` command.

### Inputs

| Name | Default | Description |
| ------------------- | ------------ | ------------------------------------- |
| `tags` | (required) | Docker image tags |
| `expected-revision` | `github.sha` | Expected Git revision of Docker image |
| `timeout-seconds` | 600 | Timeout |
| `polling-seconds` | 5 | Polling interval |
| Name | Default | Description |
| ------------------- | ----------- | -------------------------------------- |
| `tags` | (required) | Docker image tags |
| `expected-revision` | (see below) | Expected Git revisions of Docker image |
| `timeout-seconds` | 600 | Timeout |
| `polling-seconds` | 5 | Polling interval |

By default, this action waits until the revision is `github.sha` or `github.event.pull_request.head.sha`.
Since [docker/metadata-action@v4.1.0](https://github.com/docker/metadata-action/releases/tag/v4.1.0),
it generates the head sha on pull request event (see also [the issue](https://github.com/docker/metadata-action/issues/206)).
6 changes: 4 additions & 2 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ inputs:
description: Docker tags (multi-line string)
required: true
expected-revision:
description: expected Git revision
description: expected Git revisions (multi-line string)
required: true
default: ${{ github.sha }}
default: |-
${{ github.sha }}
${{ github.event.pull_request.head.sha }}
timeout-seconds:
description: timeout in seconds
required: true
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { run } from './run'
const main = async (): Promise<void> => {
await run({
tags: core.getMultilineInput('tags', { required: true }),
expectedRevision: core.getInput('expected-revision', { required: true }),
expectedRevisions: core.getMultilineInput('expected-revision', { required: true }),
timeoutSeconds: parseInt(core.getInput('timeout-seconds', { required: true })),
pollingSeconds: parseInt(core.getInput('polling-seconds', { required: true })),
})
Expand Down
7 changes: 4 additions & 3 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as exec from '@actions/exec'

type Inputs = {
tags: string[]
expectedRevision: string
expectedRevisions: string[]
timeoutSeconds: number
pollingSeconds: number
}
Expand All @@ -22,9 +22,10 @@ export const run = async (inputs: Inputs): Promise<void> => {
const checkIfDockerImageRevisionIsExpected = async (inputs: Inputs): Promise<boolean> => {
for (const tag of inputs.tags) {
const revision = await getDockerImageRevision(tag)
if (revision !== inputs.expectedRevision) {
return false
if (revision && inputs.expectedRevisions.includes(revision)) {
continue
}
return false
}
return true
}
Expand Down

0 comments on commit ef59f10

Please sign in to comment.