Skip to content

Commit 2a85640

Browse files
Hallo5000zlataovce
andauthored
feat(misc): automatic Hangar page updates (#718)
* added an explanation on how to automatically update a projects Resource Page * minor spelling mistake * refactor: cleanup --------- Co-authored-by: Matouš Kučera <mk@kcra.me>
1 parent 5f52a6a commit 2a85640

File tree

1 file changed

+65
-37
lines changed

1 file changed

+65
-37
lines changed

src/content/docs/misc/hangar-publishing.md

Lines changed: 65 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: How to automatically publish your plugin to Hangar on commits.
44
slug: misc/hangar-publishing
55
---
66

7-
If you want to automatically publish your plugin to [Hangar](https://hangar.papermc.io/) on commits, you can use
7+
If you want to automatically publish your plugin to [Hangar](https://hangar.papermc.io/) on pushes, you can use
88
our [Gradle plugin](https://github.com/HangarMC/hangar-publish-plugin).
99

1010
After you have added the required `hangarPublish` configuration, you can manually publish it by
@@ -133,11 +133,50 @@ hangarPublish {
133133
}
134134
```
135135

136-
### Optional: Going deeper
136+
## GitHub Actions workflow
137137

138-
With the following channels, any version that contains a hyphen (`-`) will be published under the `Snapshot` channel
139-
that you need to create on Hangar. By editing the `channel.set(...)` line, you can change this to any channel you would
140-
like. For example, you could further split builds depending on the branch you are currently on into `Alpha` builds.
138+
You don't necessarily need to publish via GitHub Actions, but it is an easy way to do so. If you want to use it, create
139+
a `publish.yml` file in the `.github/workflows` directory of your project root folder and make sure
140+
you [add the repository secret](#adding-the-hangar_api_token-repository-secret).
141+
142+
You can add and remove branches to be published by editing the `branches` section.
143+
144+
```yaml
145+
name: Publish to Hangar
146+
on:
147+
push:
148+
branches:
149+
# Add any additional branches you want to automatically publish from
150+
- main # Assuming your main branch is called 'main'
151+
152+
jobs:
153+
publish:
154+
# TODO: Optional, make sure the task only runs on pushes to your repository and doesn't fail on forks. Uncomment the line below and put the repo owner into the quotes
155+
# if: github.repository_owner == '<YOUR USER/ORG NAME>'
156+
runs-on: ubuntu-22.04
157+
steps:
158+
- name: Checkout Repository
159+
uses: actions/checkout@v3
160+
- name: Validate Gradle Wrapper
161+
uses: gradle/wrapper-validation-action@v1
162+
- name: Set up JDK 17
163+
uses: actions/setup-java@v3
164+
with:
165+
distribution: 'temurin'
166+
java-version: 17
167+
- name: Publish
168+
env:
169+
# Make sure you have added a repository secret in the repository's settings
170+
HANGAR_API_TOKEN: ${{ secrets.HANGAR_API_TOKEN }}
171+
run: ./gradlew build publishPluginPublicationToHangar --stacktrace
172+
```
173+
174+
## Optional: Handling multiple channels and an automatic changelog
175+
176+
With the following code, any version that contains a hyphen (`-`) will be published under the `Snapshot` channel
177+
(that you need to create on Hangar) and the others on the `Release` channel.
178+
By editing the `channel.set(...)` line, you can change this to any channel you would like.
179+
For example, you could further split builds depending on the branch you are currently on into `Alpha` builds.
141180

142181
:::caution
143182

@@ -188,40 +227,29 @@ hangarPublish {
188227
}
189228
```
190229

191-
### GitHub Actions workflow
230+
## Optional: Updating the resource page
192231

193-
You don't necessarily need to publish via GitHub Actions, but it is an easy way to do so. If you want to use it, create
194-
a `publish.yml` file in the `.github/workflows` directory of your project root folder and make sure
195-
you [add the repository secret](#adding-the-hangar_api_token-repository-secret).
232+
A notable part of publishing a new version might be updating the resource page (e.g. the plugin's home page) with new content from your plugin's repository.
196233

197-
You can add and remove branches to be published by editing the `branches` section.
234+
In this example, we're using a README file, but you can use any text you want, as long as it is in Markdown format.
198235

199-
```yaml
200-
name: Publish to Hangar
201-
on:
202-
push:
203-
branches:
204-
# Add any additional branches you want to automatically publish from
205-
- main # Assuming your main branch is called 'main'
236+
```kotlin
237+
val pageContent = project.file("README.md").readText()
206238

207-
jobs:
208-
publish:
209-
# TODO: Optional, make sure the task only runs on pushes to your repository and doesn't fail on forks. Uncomment the line below and put the repo owner into the quotes
210-
# if: github.repository_owner == '<YOUR USER/ORG NAME>'
211-
runs-on: ubuntu-22.04
212-
steps:
213-
- name: Checkout Repository
214-
uses: actions/checkout@v3
215-
- name: Validate Gradle Wrapper
216-
uses: gradle/wrapper-validation-action@v1
217-
- name: Set up JDK 17
218-
uses: actions/setup-java@v3
219-
with:
220-
distribution: 'temurin'
221-
java-version: 17
222-
- name: Publish
223-
env:
224-
# Make sure you have added a repository secret in the repository's settings
225-
HANGAR_API_TOKEN: ${{ secrets.HANGAR_API_TOKEN }}
226-
run: ./gradlew build publishPluginPublicationToHangar --stacktrace
239+
hangarPublish {
240+
publications.register("plugin") {
241+
// ... (see above)
242+
pages.resourcePage(pageContent)
243+
}
244+
}
245+
```
246+
247+
You can invoke the `syncPluginPublicationMainResourcePagePageToHangar` task to update the resource page on Hangar.
248+
This will not publish a new version, but simply update the page content on Hangar.
249+
250+
If you're using a GitHub Actions workflow, you should also add the task invocation to the `Publish` step in your workflow:
251+
```yaml
252+
- name: Publish
253+
# ...
254+
run: ./gradlew build publishPluginPublicationToHangar syncPluginPublicationMainResourcePagePageToHangar --stacktrace
227255
```

0 commit comments

Comments
 (0)