Skip to content

Commit 84d2a3d

Browse files
authored
feat(ci/publish): automate publish packages with release-please (#65)
* feat(ci/publish): automate publish packages via release-please * chore: add release-please configuration and manifest files
1 parent 5b04ac4 commit 84d2a3d

3 files changed

Lines changed: 69 additions & 46 deletions

File tree

.github/workflows/publish.yml

Lines changed: 55 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,109 @@
1-
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2-
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
3-
41
name: publish
52

63
on:
7-
workflow_dispatch:
8-
inputs:
9-
version:
10-
description: ""
11-
required: true
12-
default: "keep current"
13-
type: choice
14-
options:
15-
- "keep current"
16-
174
push:
18-
tags:
19-
- "v*.*.*"
5+
branches:
6+
- "main"
7+
8+
workflow_dispatch:
209

2110
env:
2211
default_node_version: "lts/*"
2312
artifact_name: build_${{ github.sha }}
2413

14+
concurrency: ${{ github.workflow }}-${{ github.ref }}
15+
2516
jobs:
2617
build:
2718
name: Build
2819
uses: ./.github/workflows/build.yml
2920

30-
publish-npm:
21+
release-please:
3122
needs: build
3223
runs-on: ubuntu-latest
24+
permissions:
25+
contents: write
26+
issues: write
27+
pull-requests: write
28+
outputs:
29+
release_created: ${{ steps.release_please_action.outputs.release_created }}
30+
steps:
31+
- uses: googleapis/release-please-action@v4
32+
id: release_please_action
33+
with:
34+
token: ${{ secrets.GITHUB_TOKEN }}
35+
release-type: node
36+
37+
publish-npm:
38+
if: ${{ needs.release-please.outputs.release_created }}
39+
needs: release-please
40+
runs-on: ubuntu-latest
3341
permissions:
3442
contents: read
3543
id-token: write
44+
env:
45+
registry_url: "https://registry.npmjs.org"
46+
environment:
47+
name: npmjs
48+
url: https://www.npmjs.com/create-hexo
3649
steps:
3750
- uses: actions/checkout@v6
51+
if: ${{ needs.release-please.outputs.release_created }}
3852
with:
3953
submodules: "recursive"
4054

4155
- uses: actions/download-artifact@v8
56+
if: ${{ needs.release-please.outputs.release_created }}
4257
with:
4358
name: ${{ env.artifact_name }}
4459

4560
- uses: actions/setup-node@v6
61+
if: ${{ needs.release-please.outputs.release_created }}
4662
with:
4763
node-version: ${{ env.default_node_version }}
48-
registry-url: https://registry.npmjs.org/
64+
registry-url: ${{ env.registry_url }}
4965

50-
- run: npm publish --provenance --access public --registry=https://registry.npmjs.org/
66+
- run: npm publish --provenance --access public --registry=${{ env.registry_url }}
67+
if: ${{ needs.release-please.outputs.release_created }}
5168

5269
publish-ghp:
53-
needs: build
70+
if: ${{ needs.release-please.outputs.release_created }}
71+
needs: release-please
5472
runs-on: ubuntu-latest
55-
env:
56-
SCOPE: "@${{github.repository_owner}}"
5773
permissions:
5874
contents: read
5975
packages: write
6076
id-token: write
77+
env:
78+
SCOPE: "@${{ github.repository_owner }}"
79+
registry_url: "https://npm.pkg.github.com/"
80+
environment:
81+
name: Github Packages
82+
url: https://github.com/hexojs/create-hexo/pkgs/npm/create-hexo
6183
steps:
6284
- uses: actions/checkout@v6
85+
if: ${{ needs.release-please.outputs.release_created }}
6386
with:
6487
submodules: "recursive"
6588

89+
- uses: actions/download-artifact@v8
90+
if: ${{ needs.release-please.outputs.release_created }}
91+
with:
92+
name: ${{ env.artifact_name }}
93+
6694
- uses: actions/setup-node@v6
95+
if: ${{ needs.release-please.outputs.release_created }}
6796
with:
6897
node-version: ${{ env.default_node_version }}
69-
registry-url: "https://npm.pkg.github.com/"
98+
registry-url: ${{ env.registry_url }}
7099
# Defaults to the user or organization that owns the workflow file
71-
scope: ${{env.SCOPE}}
72-
token: ${{secrets.GITHUB_TOKEN}}
73-
always-auth: true
74-
75-
- uses: actions/download-artifact@v8
76-
with:
77-
name: ${{ env.artifact_name }}
100+
scope: ${{ env.SCOPE }}
101+
token: ${{ secrets.GITHUB_TOKEN }}
78102

79103
- name: rename package name
80104
run: |
81105
node ./scripts/renamePackage.mjs
82106
83-
- run: npm publish --access public --registry=https://npm.pkg.github.com
107+
- run: npm publish --access public --registry=${{ env.registry_url }}
84108
env:
85-
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
86-
87-
release:
88-
name: Release
89-
needs: publish-npm
90-
runs-on: ubuntu-latest
91-
permissions:
92-
contents: write
93-
discussions: write
94-
steps:
95-
- name: Release
96-
uses: softprops/action-gh-release@v2
97-
if: startsWith(github.ref, 'refs/tags/')
98-
with:
99-
generate_release_notes: true
100-
discussion_category_name: "Announcements"
109+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.release-please-manifest.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
".": "0.7.0"
3+
}

release-please-config.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"release-type": "node",
3+
"changelog-type": "github",
4+
"packages": {
5+
".": {
6+
"release-type": "node",
7+
"changelog-type": "github"
8+
}
9+
},
10+
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json"
11+
}

0 commit comments

Comments
 (0)