Skip to content

feat: Added button to copy publish.yml #1071

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
5 changes: 4 additions & 1 deletion frontend/islands/CopyButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { TbCheck, TbCopy } from "tb-icons";
interface CopyButtonProps {
title: string;
text: string;
class?: string;
}

export function CopyButton(props: CopyButtonProps) {
Expand All @@ -32,7 +33,9 @@ export function CopyButton(props: CopyButtonProps) {
class={(copied.value
? "text-green-700 dark:text-green-500"
: "text-jsr-gray-700 dark:text-gray-300") +
" hover:bg-jsr-gray-100/30 dark:hover:bg-jsr-gray-700/50 p-1.5 -mx-1.5 -my-1 rounded-full"}
` hover:bg-jsr-gray-100/30 dark:hover:bg-jsr-gray-700/50 p-1.5 -mx-1.5 -my-1 rounded-full ${
props.class ?? ""
}`}
>
{copied.value ? <TbCheck /> : <TbCopy />}
</button>
Expand Down
50 changes: 29 additions & 21 deletions frontend/routes/package/publish.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2024 the JSR authors. All rights reserved. MIT license.
// deno-lint-ignore-file react-no-danger
import { HttpError, RouteConfig } from "fresh";
import type { FullUser, Package } from "../../utils/api_types.ts";
import { define } from "../../util.ts";
Expand Down Expand Up @@ -160,6 +161,25 @@ export default define.page<typeof handler>(function PackagePage({
);
});

const WORKFLOW_CODE = `\
name: Publish
on:
push:
branches:
- main

jobs:
publish:
runs-on: ubuntu-latest
<span class='bg-[rgba(134,239,172,.25)] text-[rgba(190,242,100)]'>permissions:</span>
<span class='bg-[rgba(134,239,172,.25)] text-[rgba(190,242,100)]'> contents: read</span>
<span class='bg-[rgba(134,239,172,.25)] text-[rgba(190,242,100)]'> id-token: write</span>
steps:
- uses: actions/checkout@v4
<span class='bg-[rgba(134,239,172,.25)] text-[rgba(190,242,100)]'> - name: Publish package</span>
<span class='bg-[rgba(134,239,172,.25)] text-[rgba(190,242,100)]'> run: npx jsr publish</span>
`;

function GitHubActions({ pkg, canEdit, user }: {
pkg: Package;
canEdit: boolean;
Expand Down Expand Up @@ -244,27 +264,15 @@ function GitHubActions({ pkg, canEdit, user }: {
title="Copy workflow path"
/>
</div>
<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">
<code>
{`\
name: Publish
on:
push:
branches:
- main

jobs:
publish:
runs-on: ubuntu-latest
\n`}
<span class="bg-[rgba(134,239,172,.25)] text-[rgba(190,242,100)]">{` permissions:\n`}</span>
<span class="bg-[rgba(134,239,172,.25)] text-[rgba(190,242,100)]">{` contents: read\n`}</span>
<span class="bg-[rgba(134,239,172,.25)] text-[rgba(190,242,100)]">{` id-token: write\n`}</span>
{`
steps:
- uses: actions/checkout@v4\n\n`}
<span class="bg-[rgba(134,239,172,.25)] text-[rgba(190,242,100)]">{` - name: Publish package\n`}</span>
<span class="bg-[rgba(134,239,172,.25)] text-[rgba(190,242,100)]">{` run: npx jsr publish\n`}</span>
<pre class="bg-slate-900 text-white rounded-lg rounded-tl-none p-4 mb-2 w-full max-w-full overflow-auto relative">
<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">
<CopyButton
text={WORKFLOW_CODE.replace(/<[^>]+>/g, '')}
title="Copy workflow code"
/>
</div>
<code
dangerouslySetInnerHTML={{__html: WORKFLOW_CODE}}>
</code>
</pre>

Expand Down
Loading