Skip to content

Commit 696777b

Browse files
authored
Merge pull request #555 from smartlyio/fix-multiple-use-one-job
Fix multiple use one job
2 parents b229e83 + bc2d03f commit 696777b

File tree

12 files changed

+138
-102
lines changed

12 files changed

+138
-102
lines changed

.github/templates/jobs/build.erb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
build:
2-
runs-on: <%= ubuntu_version %>
2+
runs-on: ubuntu-22.04
33
steps:
4-
- uses: actions/checkout@v3
5-
- name: Set Node.js 16.x
6-
uses: actions/setup-node@v3
4+
- uses: actions/checkout@v4
5+
- name: Set Node.js 20.x
6+
uses: actions/setup-node@v4
77
with:
8-
node-version: 16.x
8+
node-version: 20.x
99
- name: "Install"
1010
run: |
1111
npm install

.github/templates/jobs/test.erb

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
test:
2-
runs-on: <%= ubuntu_version %>
2+
runs-on: ubuntu-22.04
33
steps:
4-
- uses: actions/checkout@v3
5-
- name: Set Node.js 16.x
6-
uses: actions/setup-node@v3
4+
- uses: actions/checkout@v4
5+
- name: Set Node.js 20.x
6+
uses: actions/setup-node@v4
77
with:
8-
node-version: 16.x
8+
node-version: 20.x
99
- name: "Build action for test"
1010
run: |
1111
npm install
@@ -19,19 +19,24 @@ test:
1919
email: ${{ env.EMAIL_INPUT }}
2020
username: ${{ env.USERNAME_INPUT }}
2121
- name: Validate result
22-
env:
23-
ACTION_SUBDIR: _github_home
2422
run: |
2523
set -u
26-
cat "$RUNNER_TEMP/$ACTION_SUBDIR/id_rsa"
24+
25+
DIRECTORIES=("$RUNNER_TEMP"/_github_home_*)
26+
27+
[ "${#DIRECTORIES[@]}" -eq 1 ]
28+
29+
KEY_DIRECTORY="${DIRECTORIES[0]}"
30+
31+
cat "$RUNNER_TEMP/"*"/id_rsa"
2732
echo
2833
git config user.name
2934
git config user.email
3035
git remote get-url origin
3136
git config core.sshCommand
32-
grep '^github\.com' "$RUNNER_TEMP/$ACTION_SUBDIR/known_hosts"
37+
grep '^github\.com' "$KEY_DIRECTORY/known_hosts"
3338

34-
[[ "$(cat "$RUNNER_TEMP/$ACTION_SUBDIR/id_rsa")" == "not-a-real-key" ]]
39+
[[ "$(cat "$KEY_DIRECTORY/id_rsa")" == "not-a-real-key" ]]
3540
[[ "$(git config user.name)" == "${{ env.USERNAME_INPUT }}" ]]
3641
[[ "$(git config user.email)" == "${{ env.EMAIL_INPUT }}" ]]
3742
[[ "$(git remote get-url origin)" == "[email protected]:$GITHUB_REPOSITORY.git" ]]

.github/templates/pull_request.yml.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ jobs:
1010
@import ./jobs/test
1111

1212
release:
13-
runs-on: <%= ubuntu_version %>
13+
runs-on: ubuntu-22.04
1414
name: "Build and release action"
1515
needs: [build, test]
1616
steps:
17-
- uses: actions/checkout@v3
17+
- uses: actions/checkout@v4
1818
with:
1919
fetch-depth: 0
2020
persist-credentials: true

.github/templates/release.yml.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ jobs:
1010
@import ./jobs/test
1111

1212
release:
13-
runs-on: <%= ubuntu_version %>
13+
runs-on: ubuntu-22.04
1414
name: "Build and release action"
1515
needs: [build, test]
1616
steps:
17-
- uses: actions/checkout@v3
17+
- uses: actions/checkout@v4
1818
with:
1919
fetch-depth: 0
2020
persist-credentials: true

.github/workflows/pull_request.generated.yml

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ jobs:
1717
build:
1818
runs-on: ubuntu-22.04
1919
steps:
20-
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4
21-
- name: Set Node.js 16.x
20+
- uses: actions/checkout@v4
21+
- name: Set Node.js 20.x
2222
uses: actions/setup-node@v4
2323
with:
24-
node-version: 16.x
24+
node-version: 20.x
2525
- name: "Install"
2626
run: |
2727
npm install
@@ -42,11 +42,11 @@ jobs:
4242
test:
4343
runs-on: ubuntu-22.04
4444
steps:
45-
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4
46-
- name: Set Node.js 16.x
45+
- uses: actions/checkout@v4
46+
- name: Set Node.js 20.x
4747
uses: actions/setup-node@v4
4848
with:
49-
node-version: 16.x
49+
node-version: 20.x
5050
- name: "Build action for test"
5151
run: |
5252
npm install
@@ -60,19 +60,24 @@ jobs:
6060
email: ${{ env.EMAIL_INPUT }}
6161
username: ${{ env.USERNAME_INPUT }}
6262
- name: Validate result
63-
env:
64-
ACTION_SUBDIR: _github_home
6563
run: |
6664
set -u
67-
cat "$RUNNER_TEMP/$ACTION_SUBDIR/id_rsa"
65+
66+
DIRECTORIES=("$RUNNER_TEMP"/_github_home_*)
67+
68+
[ "${#DIRECTORIES[@]}" -eq 1 ]
69+
70+
KEY_DIRECTORY="${DIRECTORIES[0]}"
71+
72+
cat "$RUNNER_TEMP/"*"/id_rsa"
6873
echo
6974
git config user.name
7075
git config user.email
7176
git remote get-url origin
7277
git config core.sshCommand
73-
grep '^github\.com' "$RUNNER_TEMP/$ACTION_SUBDIR/known_hosts"
78+
grep '^github\.com' "$KEY_DIRECTORY/known_hosts"
7479
75-
[[ "$(cat "$RUNNER_TEMP/$ACTION_SUBDIR/id_rsa")" == "not-a-real-key" ]]
80+
[[ "$(cat "$KEY_DIRECTORY/id_rsa")" == "not-a-real-key" ]]
7681
[[ "$(git config user.name)" == "${{ env.USERNAME_INPUT }}" ]]
7782
[[ "$(git config user.email)" == "${{ env.EMAIL_INPUT }}" ]]
7883
[[ "$(git remote get-url origin)" == "[email protected]:$GITHUB_REPOSITORY.git" ]]
@@ -85,7 +90,7 @@ jobs:
8590
name: "Build and release action"
8691
needs: [build, test]
8792
steps:
88-
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4
93+
- uses: actions/checkout@v4
8994
with:
9095
fetch-depth: 0
9196
persist-credentials: true

.github/workflows/release.generated.yml

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ jobs:
1717
build:
1818
runs-on: ubuntu-22.04
1919
steps:
20-
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4
21-
- name: Set Node.js 16.x
20+
- uses: actions/checkout@v4
21+
- name: Set Node.js 20.x
2222
uses: actions/setup-node@v4
2323
with:
24-
node-version: 16.x
24+
node-version: 20.x
2525
- name: "Install"
2626
run: |
2727
npm install
@@ -42,11 +42,11 @@ jobs:
4242
test:
4343
runs-on: ubuntu-22.04
4444
steps:
45-
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4
46-
- name: Set Node.js 16.x
45+
- uses: actions/checkout@v4
46+
- name: Set Node.js 20.x
4747
uses: actions/setup-node@v4
4848
with:
49-
node-version: 16.x
49+
node-version: 20.x
5050
- name: "Build action for test"
5151
run: |
5252
npm install
@@ -60,19 +60,24 @@ jobs:
6060
email: ${{ env.EMAIL_INPUT }}
6161
username: ${{ env.USERNAME_INPUT }}
6262
- name: Validate result
63-
env:
64-
ACTION_SUBDIR: _github_home
6563
run: |
6664
set -u
67-
cat "$RUNNER_TEMP/$ACTION_SUBDIR/id_rsa"
65+
66+
DIRECTORIES=("$RUNNER_TEMP"/_github_home_*)
67+
68+
[ "${#DIRECTORIES[@]}" -eq 1 ]
69+
70+
KEY_DIRECTORY="${DIRECTORIES[0]}"
71+
72+
cat "$RUNNER_TEMP/"*"/id_rsa"
6873
echo
6974
git config user.name
7075
git config user.email
7176
git remote get-url origin
7277
git config core.sshCommand
73-
grep '^github\.com' "$RUNNER_TEMP/$ACTION_SUBDIR/known_hosts"
78+
grep '^github\.com' "$KEY_DIRECTORY/known_hosts"
7479
75-
[[ "$(cat "$RUNNER_TEMP/$ACTION_SUBDIR/id_rsa")" == "not-a-real-key" ]]
80+
[[ "$(cat "$KEY_DIRECTORY/id_rsa")" == "not-a-real-key" ]]
7681
[[ "$(git config user.name)" == "${{ env.USERNAME_INPUT }}" ]]
7782
[[ "$(git config user.email)" == "${{ env.EMAIL_INPUT }}" ]]
7883
[[ "$(git remote get-url origin)" == "[email protected]:$GITHUB_REPOSITORY.git" ]]
@@ -85,7 +90,7 @@ jobs:
8590
name: "Build and release action"
8691
needs: [build, test]
8792
steps:
88-
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4
93+
- uses: actions/checkout@v4
8994
with:
9095
fetch-depth: 0
9196
persist-credentials: true

__tests__/main.test.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import {
99
getSshPath,
1010
sshKeyscan,
1111
setupGitAction,
12-
cleanupGitAction,
13-
TEMPDIR_NAME
12+
cleanupGitAction
1413
} from '../src/setup-git-action'
1514

1615
jest.mock('@actions/core', () => ({
@@ -59,8 +58,9 @@ describe('test npm-setup-publish', () => {
5958
})
6059

6160
test('get ssh path', () => {
62-
const filePath = getSshPath('id_rsa')
63-
expect(filePath).toEqual(`${runnerTempDir}/${TEMPDIR_NAME}/id_rsa`)
61+
const directory = 'some-subdirectory'
62+
const filePath = getSshPath(directory, 'id_rsa')
63+
expect(filePath).toEqual(`${runnerTempDir}/${directory}/id_rsa`)
6464
})
6565

6666
test('ssh-keyscan', async () => {
@@ -89,11 +89,12 @@ describe('test npm-setup-publish', () => {
8989
const email = '[email protected]'
9090
const username = 'Example User'
9191
const deployKey = 'definitely an ssh key'
92+
const directory = 'a-uuid'
9293

93-
await setupGitAction(email, username, deployKey)
94+
await setupGitAction(email, username, deployKey, directory)
9495

9596
const sshKeyData = await fs.readFile(
96-
path.join(runnerTempDir as string, TEMPDIR_NAME, 'id_rsa')
97+
path.join(runnerTempDir as string, directory, 'id_rsa')
9798
)
9899
expect(sshKeyData.toString()).toEqual(`${deployKey}\n`)
99100

@@ -124,13 +125,14 @@ describe('test npm-setup-publish', () => {
124125
})
125126

126127
test('cleanupGitAction', async () => {
127-
const keyPath = path.join(runnerTempDir as string, TEMPDIR_NAME, 'id_rsa')
128+
const directory = 'a-uuid'
129+
const keyPath = path.join(runnerTempDir as string, directory, 'id_rsa')
128130
const hostsPath = path.join(
129131
runnerTempDir as string,
130-
TEMPDIR_NAME,
132+
directory,
131133
'known_hosts'
132134
)
133-
await cleanupGitAction()
135+
await cleanupGitAction(directory)
134136

135137
const mockExec = mocked(exec)
136138
expect(mockExec.mock.calls.length).toEqual(6)

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ inputs:
1010
required: false
1111
default: 'Github Action'
1212
runs:
13-
using: 'node16'
13+
using: 'node20'
1414
main: 'dist/index.js'
1515
post: 'dist/index.js'

0 commit comments

Comments
 (0)