Skip to content

Commit bdb8c2e

Browse files
authored
feat: Added button to copy publish.yml (#1071)
Preview: ![imagen](https://github.com/user-attachments/assets/c9ad3f84-aa99-421e-99a3-9815388bbedf)
1 parent aec8329 commit bdb8c2e

File tree

2 files changed

+33
-22
lines changed

2 files changed

+33
-22
lines changed

frontend/islands/CopyButton.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { TbCheck, TbCopy } from "tb-icons";
66
interface CopyButtonProps {
77
title: string;
88
text: string;
9+
class?: string;
910
}
1011

1112
export function CopyButton(props: CopyButtonProps) {
@@ -32,7 +33,9 @@ export function CopyButton(props: CopyButtonProps) {
3233
class={(copied.value
3334
? "text-green-700 dark:text-green-500"
3435
: "text-jsr-gray-700 dark:text-gray-300") +
35-
" hover:bg-jsr-gray-100/30 dark:hover:bg-jsr-gray-700/50 p-1.5 -mx-1.5 -my-1 rounded-full"}
36+
` hover:bg-jsr-gray-100/30 dark:hover:bg-jsr-gray-700/50 p-1.5 -mx-1.5 -my-1 rounded-full ${
37+
props.class ?? ""
38+
}`}
3639
>
3740
{copied.value ? <TbCheck /> : <TbCopy />}
3841
</button>

frontend/routes/package/publish.tsx

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Copyright 2024 the JSR authors. All rights reserved. MIT license.
2+
// deno-lint-ignore-file react-no-danger
23
import { HttpError, RouteConfig } from "fresh";
34
import type { FullUser, Package } from "../../utils/api_types.ts";
45
import { define } from "../../util.ts";
@@ -160,6 +161,25 @@ export default define.page<typeof handler>(function PackagePage({
160161
);
161162
});
162163

164+
const WORKFLOW_CODE = `\
165+
name: Publish
166+
on:
167+
push:
168+
branches:
169+
- main
170+
171+
jobs:
172+
publish:
173+
runs-on: ubuntu-latest
174+
<span class='bg-[rgba(134,239,172,.25)] text-[rgba(190,242,100)]'>permissions:</span>
175+
<span class='bg-[rgba(134,239,172,.25)] text-[rgba(190,242,100)]'> contents: read</span>
176+
<span class='bg-[rgba(134,239,172,.25)] text-[rgba(190,242,100)]'> id-token: write</span>
177+
steps:
178+
- uses: actions/checkout@v4
179+
<span class='bg-[rgba(134,239,172,.25)] text-[rgba(190,242,100)]'> - name: Publish package</span>
180+
<span class='bg-[rgba(134,239,172,.25)] text-[rgba(190,242,100)]'> run: npx jsr publish</span>
181+
`;
182+
163183
function GitHubActions({ pkg, canEdit, user }: {
164184
pkg: Package;
165185
canEdit: boolean;
@@ -244,27 +264,15 @@ function GitHubActions({ pkg, canEdit, user }: {
244264
title="Copy workflow path"
245265
/>
246266
</div>
247-
<pre class="bg-slate-900 dark:bg-slate-800 text-white rounded-lg rounded-tl-none p-4 mb-2 w-full max-w-full overflow-auto">
248-
<code>
249-
{`\
250-
name: Publish
251-
on:
252-
push:
253-
branches:
254-
- main
255-
256-
jobs:
257-
publish:
258-
runs-on: ubuntu-latest
259-
\n`}
260-
<span class="bg-[rgba(134,239,172,.25)] text-[rgba(190,242,100)]">{` permissions:\n`}</span>
261-
<span class="bg-[rgba(134,239,172,.25)] text-[rgba(190,242,100)]">{` contents: read\n`}</span>
262-
<span class="bg-[rgba(134,239,172,.25)] text-[rgba(190,242,100)]">{` id-token: write\n`}</span>
263-
{`
264-
steps:
265-
- uses: actions/checkout@v4\n\n`}
266-
<span class="bg-[rgba(134,239,172,.25)] text-[rgba(190,242,100)]">{` - name: Publish package\n`}</span>
267-
<span class="bg-[rgba(134,239,172,.25)] text-[rgba(190,242,100)]">{` run: npx jsr publish\n`}</span>
267+
<pre class="bg-slate-900 text-white rounded-lg rounded-tl-none p-4 mb-2 w-full max-w-full overflow-auto relative">
268+
<div class="bg-white dark:bg-jsr-gray-900 text-white rounded p-0.5 absolute top-2 right-2 z-1 size-8 flex justify-center items-center">
269+
<CopyButton
270+
text={WORKFLOW_CODE.replace(/<[^>]+>/g, '')}
271+
title="Copy workflow code"
272+
/>
273+
</div>
274+
<code
275+
dangerouslySetInnerHTML={{__html: WORKFLOW_CODE}}>
268276
</code>
269277
</pre>
270278

0 commit comments

Comments
 (0)