Skip to content

Commit 6cf1d6d

Browse files
committed
debugging for github action: last additions
1 parent 912349f commit 6cf1d6d

File tree

9 files changed

+169
-29
lines changed

9 files changed

+169
-29
lines changed

.github/actions/test-action/action.yml renamed to .github/actions/check-for-forked-repo/action.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
name: 'Test Action'
2-
description: ''
1+
name: 'Check for forked repo'
2+
description: 'Validates if comment was made on the original repo'
33

44
inputs:
55
token:
66
description: 'GitHub access token'
77
required: true
8-
test:
9-
description: 'Test variable'
10-
required: true
118

129
runs:
1310
using: 'node16'
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import core from '@actions/core';
2+
import github, {context} from '@actions/github';
3+
4+
export async function main() {
5+
const token = core.getInput('token');
6+
const octokit = github.getOctokit(token);
7+
8+
try {
9+
const pullRequest = await octokit.rest.pulls.get({
10+
/* eslint-disable @typescript-eslint/naming-convention */
11+
owner: context.repo.owner,
12+
repo: context.repo.repo,
13+
pull_number: context.issue.number,
14+
/* eslint-enable @typescript-eslint/naming-convention */
15+
});
16+
17+
if (
18+
context.payload.repository &&
19+
pullRequest.data.head.repo &&
20+
context.payload.repository.full_name !==
21+
pullRequest.data.head.repo.full_name
22+
) {
23+
const errorMessage =
24+
'`/snapit` is not supported on pull requests from forked repositories.';
25+
26+
await octokit.rest.issues.createComment({
27+
/* eslint-disable @typescript-eslint/naming-convention */
28+
issue_number: context.issue.number,
29+
owner: context.repo.owner,
30+
repo: context.repo.repo,
31+
body: errorMessage,
32+
/* eslint-enable @typescript-eslint/naming-convention */
33+
});
34+
35+
core.setFailed(errorMessage);
36+
}
37+
} catch (err) {
38+
core.setFailed(`Request failed with error ${err}`);
39+
}
40+
}
41+
42+
main().catch((err) => core.setFailed(err.message));
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: 'Create and publish snapshot release'
2+
description: 'Creates and publishes a snapshot release'
3+
4+
inputs:
5+
token:
6+
description: 'GitHub access token'
7+
required: true
8+
9+
runs:
10+
using: 'node16'
11+
main: 'index.js'
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import core from '@actions/core';
2+
import github, {context} from '@actions/github';
3+
import {getExecOutput} from '@actions/exec';
4+
5+
export async function main() {
6+
await getExecOutput('yarn changeset version --snapshot snapshot-release');
7+
8+
const releaseProcess = await getExecOutput(
9+
'yarn release --no-git-tags --snapshot --tag snapshot-release',
10+
);
11+
12+
const newTags = Array.from(
13+
releaseProcess.stdout.matchAll(/New tag:\s+([^\s\n]+)/g),
14+
).map(([_, tag]) => tag);
15+
16+
const token = core.getInput('token');
17+
const octokit = github.getOctokit(token);
18+
19+
let body: string | null = null;
20+
21+
if (newTags.length) {
22+
const [tag] = newTags;
23+
24+
body =
25+
`🫰✨ **Thanks @${context.actor}! Your snapshot has been published to npm.**\n\n` +
26+
'Test the snapshot by updating your `package.json` ' +
27+
'with the newly published version:\n\n' +
28+
`\`\`\`sh\nyarn add ${tag}\n\`\`\``;
29+
30+
core.setOutput('snapshot-created', 'true');
31+
} else {
32+
body = `💥 Snapshot creation failed!`;
33+
34+
core.setOutput('snapshot-created', 'false');
35+
}
36+
37+
await octokit.rest.issues.createComment({
38+
/* eslint-disable @typescript-eslint/naming-convention */
39+
issue_number: context.issue.number,
40+
owner: context.repo.owner,
41+
repo: context.repo.repo,
42+
body,
43+
/* eslint-enable @typescript-eslint/naming-convention */
44+
});
45+
}
46+
47+
main().catch((err) => core.setFailed(err.message));

.github/actions/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"license": "MIT",
1212
"devDependencies": {
1313
"@actions/core": "^1.10.1",
14+
"@actions/exec": "^1.1.1",
1415
"@actions/github": "^5.1.1",
1516
"typescript": "^5.2.2"
1617
}

.github/actions/test-action/index.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

.github/actions/tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"dom",
55
"dom.iterable",
66
"scripthost",
7-
"es2023"
7+
"es2022"
88
],
99
"declaration": false,
1010
"declarationMap": false,
@@ -18,7 +18,7 @@
1818
"skipLibCheck": true,
1919
"strict": true,
2020
"module": "esnext",
21-
"target": "es2020",
21+
"target": "es2022",
2222
"noEmit": false,
2323
"noEmitHelpers": true
2424
},

.github/actions/yarn.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
"@actions/http-client" "^2.0.1"
1111
uuid "^8.3.2"
1212

13+
"@actions/exec@^1.1.1":
14+
version "1.1.1"
15+
resolved "https://registry.yarnpkg.com/@actions/exec/-/exec-1.1.1.tgz#2e43f28c54022537172819a7cf886c844221a611"
16+
integrity sha512-+sCcHHbVdk93a0XT19ECtO/gIXoxvdsgQLzb2fE2/5sIZmWQuluYyjPQtrtTHdU1YzTZ7bAPN4sITq2xi1679w==
17+
dependencies:
18+
"@actions/io" "^1.0.1"
19+
1320
"@actions/github@^5.1.1":
1421
version "5.1.1"
1522
resolved "https://registry.yarnpkg.com/@actions/github/-/github-5.1.1.tgz#40b9b9e1323a5efcf4ff7dadd33d8ea51651bbcb"
@@ -27,6 +34,11 @@
2734
dependencies:
2835
tunnel "^0.0.6"
2936

37+
"@actions/io@^1.0.1":
38+
version "1.1.3"
39+
resolved "https://registry.yarnpkg.com/@actions/io/-/io-1.1.3.tgz#4cdb6254da7962b07473ff5c335f3da485d94d71"
40+
integrity sha512-wi9JjgKLYS7U/z8PPbco+PvTb/nRWjeoFlJ1Qer83k/3C5PHQi28hiVdeE2kHXmIL99mQFawx8qt/JPjZilJ8Q==
41+
3042
"@octokit/auth-token@^2.4.4":
3143
version "2.5.0"
3244
resolved "https://registry.yarnpkg.com/@octokit/auth-token/-/auth-token-2.5.0.tgz#27c37ea26c205f28443402477ffd261311f21e36"

.github/workflows/snapit-v2.yml

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,66 @@ jobs:
4040
- name: Checkout default branch
4141
uses: actions/checkout@v3
4242

43-
- name: Checks pwd and ls
44-
run: |
45-
pwd
46-
ls -la
43+
- name: Checkout pull request branch
44+
run: hub pr checkout ${{ github.event.issue.number }}
45+
env:
46+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4747

4848
- name: Install Dependencies for @shopify/draggable-github-actions
49-
working-directory: ./.github/actions
49+
working-directory: .github/actions
5050
run: yarn install --frozen-lockfile
5151

52-
- name: Run tsc
53-
working-directory: ./.github/actions
52+
- name: Run tsc for github actions
53+
working-directory: .github/actions
5454
run: yarn build
5555

56-
- name: Test Action
57-
id: test-action
58-
uses: ./.github/actions/test-action
56+
- name: Check for forked repo
57+
uses: .github/actions/check-for-forked-repo
5958
with:
6059
token: ${{ secrets.GITHUB_TOKEN }}
61-
test: hello
60+
pull_request: ${{ github.event.issue.number }}
61+
62+
- name: Reset changeset entries on changeset-release/main branch
63+
run: |
64+
if [[ $(git branch --show-current) == 'changeset-release/main' ]]; then
65+
git checkout origin/main -- .changeset
66+
fi
67+
68+
- name: Setup Node.js
69+
uses: actions/setup-node@v3
70+
with:
71+
node-version: '18.17.1'
72+
73+
- name: Install dependencies
74+
run: yarn --frozen-lockfile
75+
76+
- name: Create an .npmrc
77+
env:
78+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
79+
run: |
80+
cat << EOF > "$HOME/.npmrc"
81+
//registry.npmjs.org/:_authToken=$NPM_TOKEN
82+
EOF
83+
84+
- name: Create and publish snapshot release
85+
id: create-and-publish-snapshot-release
86+
uses: .github/actions/create-and-publish-snapshot-release
87+
with:
88+
token: ${{ secrets.GITHUB_TOKEN }}
89+
90+
- name: Add success reaction
91+
uses: peter-evans/create-or-update-comment@v2
92+
if: ${{ steps.create-and-publish-snapshot-release.outputs.snapshot-created == 'true' }}
93+
with:
94+
comment-id: ${{ github.event.comment.id }}
95+
reactions: rocket
96+
97+
- name: Add failure reaction
98+
uses: peter-evans/create-or-update-comment@v2
99+
if: ${{ steps.create-and-publish-snapshot-release.outputs.snapshot-created == 'false' }}
100+
with:
101+
comment-id: ${{ github.event.comment.id }}
102+
reactions: confused
62103

63104
- name: Set latest commit status as ${{ job.status }}
64105
uses: myrotvorets/set-commit-status-action@master

0 commit comments

Comments
 (0)