Skip to content

Commit

Permalink
More dev notes in README
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanknox committed Jan 5, 2024
1 parent 1d99e55 commit 099aced
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
# - name: 🧪 test
# run: dotnet test --no-build --no-restore

- name: 📦 publish (package) artifacts
- name: 📦 publish (compile & package) artifacts
run: |
dotnet publish src/Extension.csproj -c Release -r win-x64 --self-contained -o bin/win-x64 --no-restore -p:PublishSingleFile=true /p:IncludeNativeLibrariesForSelfExtract=true
dotnet publish src/Extension.csproj -c Release -r osx-x64 --self-contained -o bin/osx-x64 --no-restore -p:PublishSingleFile=true /p:IncludeNativeLibrariesForSelfExtract=true
Expand Down
76 changes: 71 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ When run, the extension simply outputs a short greeting message.

### Dev Container
This repo includes a [Dev Container](https://containers.dev/)
that eleminates the need to install the [GitHub CLI](https://cli.github.com/), .NET 8.0 SDK, and other tools on your local machine.
that eliminates the need to install the [GitHub CLI](https://cli.github.com/), .NET 8.0 SDK, and other tools on your local machine.

If you're using VS Code, see [Developing inside a Container](https://code.visualstudio.com/docs/devcontainers/containers).

Expand All @@ -59,17 +59,72 @@ If you're using VS Code, see [Developing inside a Container](https://code.visual

Catalog of [GitHub CLI extensions implemented in C#](https://github.com/topics/gh-extension?l=c%23)

## Developing a GitHub CLI Extension in C#

When installed, a GitHub CLI Extension is loaded by the CLI from a release in a GitHub repo.

### Creating a Repo for a GitHub CLI Extension

The name of the GitHub repo that the extension is loaded from must be in the format:
```
gh-EXTENSION-NAME
```

#### Tell the world about your Extension
If your GitHub repo and you want others to be able to find your extension, you can add the `gh-extension` repository topic to your repo. So your extension will appear on the [gh-extension topic page](https://github.com/topics/gh-extension).

See [Classifying your repository with topics](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/classifying-your-repository-with-topics)
in GitHub Docs for more info.


### Releasing a GH CLI Extensions

#### 1. Build executables for each supported platform

A separate platform-specific executable must be created for each platform that the extension should run on. Where each executable created is self-contained, and bundles the application and its dependencies, along with the .NET runtime and libraries, in a single file for the specific runtime.

The name of the of each executable must be in the format:
```
gh-<extension-Name><OS>-<architecture>[.file-extension]
```
Note: Windows executables must have a `.exe` file extension.

Examples:
|.NET runtime | OS | Architecture | Executable Name |
|-------------|----|--------------|-----------------|
| `osx-x64` | Darwin (Mac OS) | AMD 64-bit | `gh-yourext-amd64` |
| `osx-arm64` | Darwin (Mac OS) | ARM 64-bit | `gh-yourext-darwin-arm64` |
| `linux-x64` | Linux | AMD 64-bit | `gh-yourext-linux-amd64` |
| `win-x64` | Windows | AMD 64-bit | `gh-yourext-windows-amd64.exe`|

See the `build` job the `.github\workflows\ci.yml` file for details on how the platform-specific executable files are are created.

See [here](https://github.com/cli/cli/blob/14f704fd0da58cc01413ee4ba16f13f27e33d15e/pkg/cmd/extension/manager.go#L696) for a list of OS and Architecture combinations recognized by the GH CLI.

#### 2. Create a release and attached the executables
Create a release in the repo and attach each of the extension's platform-specific executables to the release.

The `publish` job in the `.github\workflows\ci.yml` file
uses the [softprops/action-gh-release](https://github.com/softprops/action-gh-release/tree/v1/) GitHub Action to create the release and attach the platform-specific executables as release artifacts.

## Building and Packaging the sample GitHub CLI Extension

A build of the sample extension is triggered on push to `main` or by pull request.
A build of the sample extension is triggered on push to `main` or on a pull request.

The `build` job defined in the `.github\workflows\ci.yml` file shows how the extension is built and then packaged for multiple target platforms.

## Creating Releases the sample GitHub CLI Extension
## Releasing the sample GitHub CLI Extension

Publishing a release of the sample extension is done in two steps
1. Creating a draft release on push or PR.
1. Manually publishing the draft release.

Details for these steps are described in the following subsections.
Along with notes for publishing the release in a single step.

### Create a Draft Release of the Extension
A draft release is created in the repo when a tag with a 'v' prefix is pushed to 'main'. For example:
A draft release of the extension is created in the repo when a tag with a 'v' prefix is pushed to 'main'.
For example:
```shell
git tag v1.2.3
git push origin v1.2.3
Expand All @@ -80,7 +135,6 @@ The `publish` job defined in the `.github\workflows\ci.yml` file shows how the d

The [softprops/action-gh-release](https://github.com/softprops/action-gh-release/tree/v1/) GitHub Action is used to create the draft release.


### Publishing a Release of the Extension
A draft release in the repo can be published by editing the release and switching it from draft to published.

Expand All @@ -91,3 +145,15 @@ gh release edit v1.2.3 --draft=false
```

Once the release is published, users can install the extension as described above.

### Automatically Create and Publish a Release of the Extension
To automatically publish a release of the extension whenever `v` prefixed tag is pushed, edit the `publish` job the `.github\workflows\ci.yml` file and set the `draft` input to `false`.

```yaml
- name: 🚀 create and publish release
uses: softprops/action-gh-release@v1
with:
draft: false
. . .
```
See [softprops/action-gh-release](https://github.com/softprops/action-gh-release/tree/v1/)

0 comments on commit 099aced

Please sign in to comment.