Skip to content

Commit 1615590

Browse files
committed
Upgrade workflows
1 parent 4f09481 commit 1615590

File tree

7 files changed

+110
-53
lines changed

7 files changed

+110
-53
lines changed

.github/workflows/format-code.yml renamed to .github/workflows/action-format.yml

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: 'Format code'
1+
name: 'javascript-lib-static-analysis / format'
22

33
on:
44
issue_comment:
@@ -7,16 +7,16 @@ on:
77
jobs:
88
format:
99
name: 'Format code'
10-
runs-on: ubuntu-latest
10+
runs-on: ubuntu-22.04
1111
if: github.event.issue.pull_request != '' && contains(github.event.comment.body, '/format')
1212
steps:
1313
- name: 'Post acknowledgement that it will format code'
1414
continue-on-error: true # Never fail the build if this fails
15-
uses: actions/github-script@6e5ee1dc1cb3740e5e5e76ad668e3f526edbfe45 # 2.0.0
15+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
1616
with:
1717
github-token: ${{ secrets.GITHUB_TOKEN }}
1818
script: |
19-
github.issues.createComment({
19+
github.rest.issues.createComment({
2020
issue_number: context.issue.number,
2121
owner: context.repo.owner,
2222
repo: context.repo.repo,
@@ -34,7 +34,7 @@ jobs:
3434
id: fork_status
3535
run: |
3636
IS_FORK="$(jq '.head.repo.fork' "/tmp/pr.json")"
37-
echo "::set-output name=fork::$IS_FORK"
37+
echo "fork=$IS_FORK" >> "$GITHUB_OUTPUT"
3838
3939
- name: 'Setup SSH deploy key'
4040
if: steps.fork_status.outputs.fork == 'false'
@@ -60,6 +60,10 @@ jobs:
6060
git clone $HEAD_REPO .
6161
git checkout -b "$HEAD_REF" "origin/$HEAD_REF"
6262
63+
- name: Use Node.js LTS (20.x)
64+
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b
65+
with:
66+
node-version: 20.x
6367
- name: 'Format code'
6468
run: ./bin/format.sh
6569

@@ -82,11 +86,11 @@ jobs:
8286
8387
- name: 'Post acknowledgement that it has formatted the code'
8488
continue-on-error: true # Never fail the build if this fails
85-
uses: actions/github-script@6e5ee1dc1cb3740e5e5e76ad668e3f526edbfe45 # 2.0.0
89+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
8690
with:
8791
github-token: ${{ secrets.GITHUB_TOKEN }}
8892
script: |
89-
github.issues.createComment({
93+
github.rest.issues.createComment({
9094
issue_number: context.issue.number,
9195
owner: context.repo.owner,
9296
repo: context.repo.repo,
@@ -96,11 +100,11 @@ jobs:
96100
- name: 'Post reminder to trigger build manually'
97101
continue-on-error: true # Never fail the build if this fails
98102
if: steps.fork_status.outputs.fork == 'true'
99-
uses: actions/github-script@6e5ee1dc1cb3740e5e5e76ad668e3f526edbfe45 # 2.0.0
103+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
100104
with:
101105
github-token: ${{ secrets.GITHUB_TOKEN }}
102106
script: |
103-
github.issues.createComment({
107+
github.rest.issues.createComment({
104108
issue_number: context.issue.number,
105109
owner: context.repo.owner,
106110
repo: context.repo.repo,

.github/workflows/ci.js.yml

+11-11
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,34 @@ on:
99

1010
jobs:
1111
precheck:
12-
runs-on: ubuntu-latest
12+
runs-on: ubuntu-22.04
1313

1414
steps:
15-
- uses: actions/checkout@v2
16-
- name: Use Node.js LTS (16.x)
17-
uses: actions/setup-node@v1
15+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
16+
- name: Use Node.js LTS (20.x)
17+
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b
1818
with:
19-
node-version: 16.x
19+
node-version: 20.x
2020

2121
- name: Install project dependencies
22-
run: yarn install --frozen-lockfile --ignore-scripts
22+
run: yarn install --immutable
2323

2424
- name: Lint code
2525
run: yarn lint
2626

2727
ci:
28-
runs-on: ubuntu-latest
28+
runs-on: ubuntu-22.04
2929

3030
strategy:
3131
matrix:
32-
node-version: [14.x, 16.x]
32+
node-version: [20.x, 22.x]
3333

3434
steps:
35-
- uses: actions/checkout@v2
35+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
3636
- name: Use Node.js ${{ matrix.node-version }}
37-
uses: actions/setup-node@v1
37+
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b
3838
with:
3939
node-version: ${{ matrix.node-version }}
4040

4141
- name: Install project dependencies and run tests
42-
run: yarn install --frozen-lockfile
42+
run: yarn install --immutable

.github/workflows/pr.ci.js.yml

+11-11
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,38 @@ on: pull_request
77

88
jobs:
99
precheck:
10-
runs-on: ubuntu-latest
10+
runs-on: ubuntu-22.04
1111

1212
steps:
1313
- name: Checkout PR
14-
uses: actions/checkout@v2
14+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
1515

16-
- name: Use Node.js LTS (16.x)
17-
uses: actions/setup-node@v1
16+
- name: Use Node.js LTS (20.x)
17+
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b
1818
with:
19-
node-version: 16.x
19+
node-version: 20.x
2020

2121
- name: Install project dependencies
22-
run: yarn install --frozen-lockfile --ignore-scripts
22+
run: yarn install --immutable
2323

2424
- name: Lint code
2525
run: yarn lint
2626

2727
ci:
28-
runs-on: ubuntu-latest
28+
runs-on: ubuntu-22.04
2929

3030
strategy:
3131
matrix:
32-
node-version: [14.x, 16.x]
32+
node-version: [20.x, 22.x]
3333

3434
steps:
3535
- name: Checkout PR
36-
uses: actions/checkout@v2
36+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
3737

3838
- name: Use Node.js ${{ matrix.node-version }}
39-
uses: actions/setup-node@v1
39+
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b
4040
with:
4141
node-version: ${{ matrix.node-version }}
4242

4343
- name: Install project dependencies and run tests
44-
run: yarn install --frozen-lockfile
44+
run: yarn install --immutable

.github/workflows/verify-code-formatting.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ on:
77

88
jobs:
99
verify:
10-
runs-on: ubuntu-latest
10+
runs-on: ubuntu-22.04
1111
steps:
1212
- name: 'Checkout code'
13-
uses: actions/checkout@v2
13+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
1414

1515
- name: 'Verify formatting of all files'
1616
run: ./bin/check-formatting.sh

bin/check-formatting.sh

+34-10
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,51 @@
11
#!/usr/bin/env bash
22

3-
if [ -z "$EXERCISM_PRETTIER_VERSION" ]; then
4-
echo "Pulling prettier version from package.json"
5-
EXERCISM_PRETTIER_VERSION=$(yarn list --pattern prettier | grep -Po '.*\sprettier@\K.*')
3+
set -uo pipefail
4+
5+
if [ -z "${EXERCISM_PRETTIER_VERSION:-}" ]; then
6+
echo "[format] pulling prettier version from yarn.lock using sed"
7+
EXERCISM_PRETTIER_VERSION="$(yarn info prettier --json --name-only | sed -n -e 's/^"prettier@npm://' -e 's/"//p')"
8+
echo "[format] expected version is now ${EXERCISM_PRETTIER_VERSION:-}"
9+
fi
10+
11+
if [ -z "${EXERCISM_PRETTIER_VERSION:-}" ]; then
12+
echo "Version could not be pulled using sed" >&2
13+
echo "[format] pulling prettier version from yarn.lock using grep"
14+
EXERCISM_PRETTIER_VERSION="$(yarn info prettier --json --name-only | grep -Po '"prettier@npm:\K[^"]+')"
15+
echo "[format] expected version is now ${EXERCISM_PRETTIER_VERSION:-}"
616
fi
717

8-
if [ -z "$EXERCISM_PRETTIER_VERSION" ]; then
18+
if [ -z "${EXERCISM_PRETTIER_VERSION:-}" ]; then
19+
echo "Version could not be pulled using grep or sed" >&2
20+
echo ""
921
echo "---------------------------------------------------"
1022
echo "This script requires the EXERCISM_PRETTIER_VERSION variable to work."
1123
echo "Please see https://exercism.org/docs/building/markdown/style-guide for guidance."
1224
echo "---------------------------------------------------"
13-
echo "This is what yarn list reports:"
14-
echo "$(yarn list prettier)"
25+
echo "$(yarn -v)"
26+
echo ""
27+
echo "This is what yarn why reports:"
28+
echo "$ yarn why prettier"
29+
echo "$(yarn why prettier)"
30+
echo ""
31+
echo "And yarn info reports the following:"
32+
echo "$ yarn info prettier --name-only"
33+
echo "$(yarn info prettier --name-only)"
34+
echo ""
35+
echo "This is the version that can be extracted using grep:"
36+
echo "$ yarn info prettier --json --name-only | grep -Po '"prettier@npm:\K[^"]+'"
37+
echo "└─ $(yarn info prettier --json --name-only | grep -Po '"prettier@npm:\K[^"]+')"
1538
echo ""
16-
echo "This is the version that can be extracted:"
17-
echo "$(yarn list --pattern prettier | grep -Po '.*\sprettier@\K.*')"
39+
echo "This is the version that can be extracted using sed:"
40+
echo "$ yarn info prettier --json --name-only | sed -n -e 's/^"prettier@npm://' -e 's/"//p'"
41+
echo "└─ $(yarn info prettier --json --name-only | sed -n -e 's/^"prettier@npm://' -e 's/"//p')"
1842
echo ""
1943
echo "These files are found in the repo root:"
2044
echo "$(ls -p | grep -v /)"
2145
echo "---------------------------------------------------"
2246
exit 1
2347
else
24-
echo "Running format with prettier@$EXERCISM_PRETTIER_VERSION"
48+
echo "[format] running with prettier@$EXERCISM_PRETTIER_VERSION"
2549
fi
2650

27-
npx "prettier@$EXERCISM_PRETTIER_VERSION" --check "**/*.{js,jsx,ts,tsx,css,sass,scss,html,json,md,yml}"
51+
yarn dlx "prettier@$EXERCISM_PRETTIER_VERSION" --check "**/*.{js,jsx,ts,tsx,css,sass,scss,html,json,md,yml}"

bin/format.sh

+34-10
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,51 @@
11
#!/usr/bin/env bash
22

3-
if [ -z "$EXERCISM_PRETTIER_VERSION" ]; then
4-
echo "Pulling prettier version from package.json"
5-
EXERCISM_PRETTIER_VERSION=$(yarn list --pattern prettier | grep -Po '.*\sprettier@\K.*')
3+
set -uo pipefail
4+
5+
if [ -z "${EXERCISM_PRETTIER_VERSION:-}" ]; then
6+
echo "[format] pulling prettier version from yarn.lock using sed"
7+
EXERCISM_PRETTIER_VERSION="$(yarn info prettier --json --name-only | sed -n -e 's/^"prettier@npm://' -e 's/"//p')"
8+
echo "[format] expected version is now ${EXERCISM_PRETTIER_VERSION:-}"
9+
fi
10+
11+
if [ -z "${EXERCISM_PRETTIER_VERSION:-}" ]; then
12+
echo "Version could not be pulled using sed" >&2
13+
echo "[format] pulling prettier version from yarn.lock using grep"
14+
EXERCISM_PRETTIER_VERSION="$(yarn info prettier --json --name-only | grep -Po '"prettier@npm:\K[^"]+')"
15+
echo "[format] expected version is now ${EXERCISM_PRETTIER_VERSION:-}"
616
fi
717

8-
if [ -z "$EXERCISM_PRETTIER_VERSION" ]; then
18+
if [ -z "${EXERCISM_PRETTIER_VERSION:-}" ]; then
19+
echo "Version could not be pulled using grep or sed" >&2
20+
echo ""
921
echo "---------------------------------------------------"
1022
echo "This script requires the EXERCISM_PRETTIER_VERSION variable to work."
1123
echo "Please see https://exercism.org/docs/building/markdown/style-guide for guidance."
1224
echo "---------------------------------------------------"
13-
echo "This is what yarn list reports:"
14-
echo "$(yarn list prettier)"
25+
echo "$(yarn -v)"
26+
echo ""
27+
echo "This is what yarn why reports:"
28+
echo "$ yarn why prettier"
29+
echo "$(yarn why prettier)"
30+
echo ""
31+
echo "And yarn info reports the following:"
32+
echo "$ yarn info prettier --name-only"
33+
echo "$(yarn info prettier --name-only)"
34+
echo ""
35+
echo "This is the version that can be extracted using grep:"
36+
echo "$ yarn info prettier --json --name-only | grep -Po '"prettier@npm:\K[^"]+'"
37+
echo "└─ $(yarn info prettier --json --name-only | grep -Po '"prettier@npm:\K[^"]+')"
1538
echo ""
16-
echo "This is the version that can be extracted:"
17-
echo "$(yarn list --pattern prettier | grep -Po '.*\sprettier@\K.*')"
39+
echo "This is the version that can be extracted using sed:"
40+
echo "$ yarn info prettier --json --name-only | sed -n -e 's/^"prettier@npm://' -e 's/"//p'"
41+
echo "└─ $(yarn info prettier --json --name-only | sed -n -e 's/^"prettier@npm://' -e 's/"//p')"
1842
echo ""
1943
echo "These files are found in the repo root:"
2044
echo "$(ls -p | grep -v /)"
2145
echo "---------------------------------------------------"
2246
exit 1
2347
else
24-
echo "Running format with prettier@$EXERCISM_PRETTIER_VERSION"
48+
echo "[format] running with prettier@$EXERCISM_PRETTIER_VERSION"
2549
fi
2650

27-
npx "prettier@$EXERCISM_PRETTIER_VERSION" --write "**/*.{js,jsx,ts,tsx,css,sass,scss,html,json,md,yml}"
51+
yarn dlx "prettier@$EXERCISM_PRETTIER_VERSION" --write "**/*.{js,jsx,ts,tsx,css,sass,scss,html,json,md,yml}"

bin/lint.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
yarn lint

0 commit comments

Comments
 (0)