Skip to content

Commit 03c68e7

Browse files
committed
article: Added the draft version for the how to publish a component
1 parent 02f96e4 commit 03c68e7

File tree

5 files changed

+227
-0
lines changed

5 files changed

+227
-0
lines changed
47.9 KB
Loading
47.9 KB
Loading
76.6 KB
Loading
821 KB
Loading
Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
---
2+
title: "How to publish an ESP-IDF component on the Registry"
3+
date: 2025-01-14
4+
showAuthor: false
5+
authors:
6+
- "pedro-minatel"
7+
tags: ["I2C", "Registry", "Component", "ESP-IDF", "Driver", "Library"]
8+
---
9+
10+
### Publishing the component to the ESP-Registry
11+
12+
Now we have everything needed to read the SHTC3 sensor, we need to publish the component to the Component Registry. To do that, there are 2 ways:
13+
14+
- Manual
15+
- GitHub Action
16+
17+
The manual procedure can be found in the [Publish the Component](https://docs.espressif.com/projects/idf-component-manager/en/latest/guides/packaging_components.html#publish-the-component) section in the documentation.
18+
19+
Alternatively to the manual procedure, we can use GitHub Actions to publish every new version of the component automatically.
20+
21+
On this article, we will focus on the GitHub Action procedure.
22+
23+
#### GitHub Actions
24+
25+
If you are not familiar with GitHub Actions, you can read the [official documentation](https://github.com/features/actions).
26+
27+
In sum, GitHub Action is a continuous integration and continuous delivery (CI/CD) platform that automates workflows right on in your GitHub repository. You can use GitHub Actions in a vast situations and you can automate for example the component publishing process.
28+
29+
#### Workflow
30+
31+
To use the actions, we need to create a folder on the root directory of your component repository, named `.github` (do not forget the dot).
32+
33+
Inside this folder, create another folder named `workflows`. On this folder, two workflow files will be created.
34+
35+
- `build_examples.yml`: This workflow will build the component example.
36+
- `upload_components.yml`: This workflow will upload the component to the registry.
37+
38+
The folder structure will be:
39+
40+
```text
41+
.
42+
.github
43+
└── workflows
44+
└── build_examples.yml
45+
└── upload_components.yml
46+
└── shtc3
47+
```
48+
49+
**build_examples.yml**
50+
51+
The build workflow will compile the example with the ESP-IDF version specified in the `idf_ver` and will run when you push to the main branch or create a PR (pull request).
52+
53+
This workflow is important to ensure that the code can be built successfully, preventing any potential issues before uploading the component to the registry.
54+
55+
```yaml
56+
name: 'build'
57+
58+
on:
59+
push:
60+
branches:
61+
- 'main'
62+
pull_request:
63+
types: [opened, reopened, synchronize]
64+
65+
jobs:
66+
build:
67+
name: build target
68+
runs-on: ubuntu-latest
69+
strategy:
70+
fail-fast: false
71+
matrix:
72+
espidf_target:
73+
- esp32
74+
- esp32c3
75+
- esp32c6
76+
- esp32h2
77+
- esp32p4
78+
- esp32s2
79+
- esp32s3
80+
examples_path:
81+
- 'shtc3/examples/shtc3_read'
82+
steps:
83+
- name: Checkout repository
84+
uses: actions/checkout@v4
85+
with:
86+
submodules: 'recursive'
87+
- name: Build Test Application with ESP-IDF
88+
uses: espressif/[email protected]
89+
with:
90+
esp_idf_version: "latest"
91+
target: ${{ matrix.espidf_target }}
92+
path: ${{ matrix.examples_path }}
93+
```
94+
95+
You can modify this workflow as you wish, like adding more examples to be tested, remove targets that you do not need, or adding different ESP-IDF versions to be tested.
96+
97+
**upload_components.yml**
98+
99+
To publish the component, the workflow `upload_component` will process the component by using the [upload-components-ci-action](https://github.com/espressif/upload-components-ci-action).
100+
101+
This workflow will run only when the component is pushed to the main branch. This avoids publishing the component before merging the branch to the main.
102+
103+
An important note is that the action will only publish the component if there is no component published with the same version. This means that you need to change the version in the manifest file before running this workflow.
104+
105+
```yaml
106+
name: Push components to Espressif Component Service
107+
108+
on:
109+
push:
110+
branches:
111+
- main
112+
113+
jobs:
114+
upload_components:
115+
runs-on: ubuntu-latest
116+
steps:
117+
- uses: actions/checkout@master
118+
119+
- name: Upload components to component service
120+
uses: espressif/upload-components-ci-action@v1
121+
with:
122+
directories: >
123+
shtc3;
124+
namespace: "<namespace>"
125+
api_token: ${{ secrets.IDF_COMPONENT_API_TOKEN }}
126+
```
127+
128+
Replace the `namespace` with your GitHub username or organization.
129+
130+
In order to upload the component, you need to provide the API key. This key is a secret and **cannot be public**.
131+
132+
**Create the Action secret**
133+
134+
GitHub has the [secret tokens](https://docs.github.com/en/actions/security-for-github-actions/security-guides/using-secrets-in-github-actions) manager that you can use in the Actions workflow.
135+
136+
To create the API token, go to [tokens](https://components.espressif.com/settings/tokens/) in the Registry and create a new token with `write:components`scope. Make sure to copy the token and store a copy in a safe place. Once you create the token, you will not be able see the full token later.
137+
138+
Now, on your GitHub repository, create a new secret token with the name `IDF_COMPONENT_API_TOKEN` and add the API token as the secret. This secret will be only accessed by the actions inside your repository.
139+
140+
After everything created, you can push all the files to a branch on your repository, test the workflow run and if all goes green (in the actions tab), you can merge and see your component published.
141+
142+
<figure style="width: 90%; margin: 0 auto; text-align: center;">
143+
<img
144+
src="./assets/esp-registry-shtc3.webp"
145+
alt="ESP-Registry SHTC3 Component"
146+
title="ESP-Registry SHTC3 Component"
147+
style="width: 100%;"
148+
/>
149+
<figcaption>ESP-Registry SHTC3 Component</figcaption>
150+
</figure>
151+
152+
For this article, the published component can be found in the Registry: [SHTC3](https://components.espressif.com/components/pedrominatel/shtc3/)
153+
154+
## Using the component
155+
156+
This is the time for testing the published component. For that, we will use the component published for this article, the [SHTC3](https://components.espressif.com/components/pedrominatel/shtc3/). After your own component is published, you can use the same approach.
157+
158+
On the component page, you will see the command from the `idf.py` to add the component to your project. In this case:
159+
160+
```bash
161+
idf.py add-dependency "pedrominatel/shtc3^1.1.0"
162+
```
163+
164+
Run this command inside a project that you want to add the component. By running this command, a new `idf_component.yml` will be added to your project with the new requirement/dependency for your project.
165+
166+
Now you can set the target and build the example (in case you are using the ESP32-C3):
167+
168+
```bash
169+
idf.py set-target esp32c3
170+
idf.py build flash monitor
171+
```
172+
173+
In the build output in the console, you will note this:
174+
175+
```text
176+
Processing 2 dependencies:
177+
[1/2] pedrominatel/shtc3 (1.1.0)
178+
[2/2] idf (5.4.0)
179+
```
180+
181+
Once you build the project, the build system will automatically download all dependencies to a folder called `managed_components`.
182+
183+
If you are not able to see the dependencies or the `managed_components` folder, you can try:
184+
185+
```bash
186+
idf.py reconfigure
187+
```
188+
189+
Another way is to create a new project based on the component example.
190+
191+
<figure style="width: 90%; margin: 0 auto; text-align: center;">
192+
<img
193+
src="./assets/esp-registry-shtc3.webp"
194+
alt="ESP-Registry SHTC3 Component example"
195+
title="ESP-Registry SHTC3 Component example"
196+
style="width: 100%;"
197+
/>
198+
<figcaption>ESP-Registry SHTC3 Component example</figcaption>
199+
</figure>
200+
201+
```bash
202+
idf.py create-project-from-example "pedrominatel/shtc3^1.1.0:shtc3_read"
203+
```
204+
205+
Set the target, build, and flash.
206+
207+
```bash
208+
cd shtc3_read
209+
idf.py set-target esp32c3
210+
idf.py build flash monitor
211+
```
212+
213+
With this command, a new project based on the example will be created. You can just set the target, configure according to your board GPIO, build and flash.
214+
215+
## Conclusion
216+
217+
Publishing a component is not just about sharing code—it’s about sharing knowledge. When you contribute a component to the registry, you’re helping developers solve challenges and build better solutions. Depending on the impact and adoption of your component, you may gain recognition and appreciation from the developer community.
218+
219+
This article is not just a guide on how to create an I2C component; it’s an encouragement for you to start sharing your work and expertise with others. Every contribution helps build a stronger, more collaborative community.
220+
221+
## Reference
222+
223+
- [ESP-Registry](https://components.espressif.com/)
224+
- [ESP-Registry Documentation](https://docs.espressif.com/projects/idf-component-manager/en/latest/)
225+
- [Compote Documentation](https://docs.espressif.com/projects/idf-component-manager/en/latest/reference/compote_cli.html)
226+
- [Component Examples](https://github.com/espressif/esp-bsp/tree/master/components)
227+
- [My Components](https://components.espressif.com/components?q=ns%3Apedrominatel)

0 commit comments

Comments
 (0)