Skip to content

Commit 5c3b7e9

Browse files
authored
Merge pull request #4 from pollenjp/feature/publish-prepare
update
2 parents f2aba91 + 2d8d7b2 commit 5c3b7e9

File tree

8 files changed

+57
-11
lines changed

8 files changed

+57
-11
lines changed

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
11
# setup-shfmt
22

3-
- Install shfmt and cache it for GitHub Actions
3+
- Install [shfmt](https://github.com/mvdan/sh) and cache it for GitHub Actions
4+
- Caching makes it especially efficient when using self-hosted runners
5+
6+
## Usage
7+
8+
```yaml
9+
jobs:
10+
shfmt:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: pollenjp/setup-shfmt@v1
14+
with:
15+
version: latest
16+
- uses: actions/checkout@v4
17+
- name: Run shfmt
18+
run: shfmt -d .
19+
```

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: 'setup-shfmt'
1+
name: 'setup-shfmt-action'
22
description: 'Install shfmt and cache it for GitHub Actions'
33
author: 'pollenJP'
44

badges/coverage.svg

Lines changed: 1 addition & 1 deletion
Loading

dist/index.js

Lines changed: 13 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "setup-shfmt",
33
"description": "Install shfmt and cache it for GitHub Actions",
4-
"version": "1.0.0",
4+
"version": "1.0.1",
55
"author": "pollenJP",
66
"private": true,
77
"homepage": "https://github.com/pollenjp/setup-shfmt",

src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export const REPO = 'sh'
22
export const OWNER = 'mvdan'
33
export const TOOL_CACHE_NAME = 'shfmt'
44
export const CMD_NAME = 'shfmt'
5+
export const RETRY_COUNT = 3

src/shfmt.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ import * as core from '@actions/core'
22
import * as tc from '@actions/tool-cache'
33
import * as os from 'os'
44
import { versionInput } from './inputs'
5-
import { CMD_NAME, OWNER, REPO, TOOL_CACHE_NAME } from './constants'
5+
import {
6+
CMD_NAME,
7+
OWNER,
8+
REPO,
9+
TOOL_CACHE_NAME,
10+
RETRY_COUNT
11+
} from './constants'
612
import { exec } from 'child_process'
713
export const setupShfmt = async (): Promise<void> => {
814
const version = await getVersion(versionInput)
@@ -43,9 +49,21 @@ const getVersion = async (version: string): Promise<string> => {
4349
switch (version) {
4450
case 'latest': {
4551
// curl -s https://api.github.com/repos/mvdan/sh/releases/latest | jq -r '.tag_name'
46-
const response = await fetch(
47-
`https://api.github.com/repos/${OWNER}/${REPO}/releases/latest`
48-
)
52+
53+
const response = await (async () => {
54+
for (let i = 0; i < RETRY_COUNT; i++) {
55+
try {
56+
return await fetch(
57+
`https://api.github.com/repos/${OWNER}/${REPO}/releases/latest`
58+
)
59+
} catch (error) {
60+
core.warning(
61+
`Failed to get the latest version of shfmt. (${(error as Error).message}) Retry... ${i + 1}/${RETRY_COUNT}`
62+
)
63+
}
64+
}
65+
throw new Error('Failed to get the latest version of shfmt.')
66+
})()
4967
const releaseResponse: ReleaseResponse =
5068
(await response.json()) as ReleaseResponse
5169
const tagName: string = releaseResponse.tag_name

0 commit comments

Comments
 (0)