Skip to content

Commit e59ec70

Browse files
authored
Add Packagist Publishing Guide (#48)
1 parent 5958d38 commit e59ec70

File tree

4 files changed

+120
-2
lines changed

4 files changed

+120
-2
lines changed
350 KB
Loading
338 KB
Loading
441 KB
Loading

fern/products/sdks/overview/php/publishing-to-packagist.mdx

Lines changed: 120 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,124 @@ title: Publishing to Packagist
33
description: How to publish the Fern PHP SDK to Packagist.
44
---
55

6-
Learn how to publish your Fern PHP SDK to the Packagist registry.
6+
Publish your public-facing Fern PHP SDK to the [Packagist
7+
registry](https://packagist.org/). After following the steps on this page,
8+
you'll have a versioned package published on Packagist.
79

8-
<Warning>This page is a WIP, please refer to our previous [documentation](https://buildwithfern.com/learn/sdks/guides/publish-a-public-facing-sdk).</Warning>
10+
<Frame>
11+
<img src="assets/packagist-package.png" alt="Versioned package published on Packagist" />
12+
</Frame>
13+
14+
<Info>This guide assumes that you already have an initialized `fern` folder on your local machine. If you don’t, run `fern init`. See [PHP Quickstart](quickstart.mdx) for more details.</Info>
15+
16+
## Set up your GitHub integration
17+
18+
1. Create a new GitHub repository called `company-php` (or something similar) for your SDK, if you haven't done so already.
19+
<Warning>
20+
Your repository must:
21+
* Have **public** visibility. You can configure this in your repository's
22+
**Settings**.
23+
* Have a `composer.json` file in your main branch that adheres to Packagist's
24+
requirements. See Packagist's [Getting
25+
Started](https://packagist.org/) and [Naming
26+
Conventions](https://packagist.org/about#naming-your-package) documentation.
27+
</Warning>
28+
1. Install the [Fern GitHub App](https://github.com/apps/fern-api): Select **Configure**, then scroll down to **Repository Access**. Select **Only select repositories** and in the dropdown select the repository for your SDK. Click **Save**.
29+
30+
31+
## Configure `generators.yml`
32+
33+
<Steps>
34+
35+
<Step title="Run `fern add <generator>`">
36+
37+
Navigate to your `generators.yml` on your local machine. Your `generators.yml` lives inside of your `fern` folder and contains all the configuration for your Fern generators.
38+
39+
Add a new generator to `generators.yml`:
40+
41+
42+
```bash
43+
fern add fern-php-sdk --group php-sdk
44+
```
45+
46+
Once the command completes, you'll see a new group created in your `generators.yml`:
47+
48+
```yaml {2-8}
49+
groups:
50+
php-sdk:
51+
generators:
52+
- name: fernapi/fern-php-sdk
53+
version: <Markdown src="/snippets/version-number.mdx"/>
54+
output:
55+
location: local-file-system
56+
path: ../sdks/php
57+
```
58+
59+
</Step>
60+
61+
62+
<Step title="Add repository location">
63+
64+
PHP publishes via Git repositories, so remove the auto-generated `output`, `location`, and `path` fields. Instead, add the path to your GitHub repository:
65+
66+
```yaml {6-7}
67+
groups:
68+
php-sdk:
69+
generators:
70+
- name: fernapi/fern-php-sdk
71+
version: <Markdown src="/snippets/version-number.mdx"/>
72+
github:
73+
repository: your-org/company-php
74+
```
75+
76+
</Step>
77+
</Steps>
78+
79+
80+
## Set up Packagist publishing authentication
81+
82+
<Steps>
83+
<Step title="Log into Packagist">
84+
85+
Log into [Packagist](https://packagist.org/login/) or [create an account with Packagist](https://packagist.org/register/).
86+
87+
</Step>
88+
<Step title="Submit the Repository URL">
89+
90+
1. Click **Submit**.
91+
1. Input the full URL of the repository where you generated your PHP SDK, then click **Check**.
92+
1. Fix any errors Packagist finds in your repository, then click **Submit**.
93+
94+
<Frame>
95+
<img src="assets/submit-package.png" alt="Submit Package Screen in Packagist" />
96+
</Frame>
97+
98+
</Step>
99+
100+
<Step title="Configure the GitHub Hook">
101+
102+
Once you've submitted your URL, you'll be prompted to set up the GitHub Hook.
103+
104+
1. In to your repository, go to **Settings > Webhooks**.
105+
1. Select **"Add webhook"**
106+
1. Set the Payload URL as `https://packagist.org/api/github?username=<your.packagist.username>`
107+
1. Set the content type as `application/json`
108+
1. Packagist autogenerates API Tokens. To find yours, go to your **Profile**. Then, add your token to the **Secret** field.
109+
1. Set the trigger events as **Just the `push` event**
110+
1. Click **"Add Webhook"**
111+
<Frame>
112+
<img src="assets/webhook.png" alt="GitHub Webhook for Packagist" />
113+
</Frame>
114+
</Step>
115+
</Steps>
116+
117+
## Release your SDK to Packagist
118+
119+
At this point, you're ready to regenerate your SDK and publish it on Packagist:
120+
121+
```bash
122+
fern generate --group php-sdk --version <version>
123+
```
124+
Local machine output will verify that the release is pushed to your
125+
repository and tagged with the version you specified. Log back into Packagist, click on your username, and select **My packages** to see your new release.
126+

0 commit comments

Comments
 (0)