|
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 | | - |
4 | 1 | name: publish |
5 | 2 |
|
6 | 3 | 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 | | - |
17 | 4 | push: |
18 | | - tags: |
19 | | - - "v*.*.*" |
| 5 | + branches: |
| 6 | + - "main" |
| 7 | + |
| 8 | + workflow_dispatch: |
20 | 9 |
|
21 | 10 | env: |
22 | 11 | default_node_version: "lts/*" |
23 | 12 | artifact_name: build_${{ github.sha }} |
24 | 13 |
|
| 14 | + concurrency: ${{ github.workflow }}-${{ github.ref }} |
| 15 | + |
25 | 16 | jobs: |
26 | 17 | build: |
27 | 18 | name: Build |
28 | 19 | uses: ./.github/workflows/build.yml |
29 | 20 |
|
30 | | - publish-npm: |
| 21 | + release-please: |
31 | 22 | needs: build |
32 | 23 | 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 |
33 | 41 | permissions: |
34 | 42 | contents: read |
35 | 43 | 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 |
36 | 49 | steps: |
37 | 50 | - uses: actions/checkout@v6 |
| 51 | + if: ${{ needs.release-please.outputs.release_created }} |
38 | 52 | with: |
39 | 53 | submodules: "recursive" |
40 | 54 |
|
41 | 55 | - uses: actions/download-artifact@v8 |
| 56 | + if: ${{ needs.release-please.outputs.release_created }} |
42 | 57 | with: |
43 | 58 | name: ${{ env.artifact_name }} |
44 | 59 |
|
45 | 60 | - uses: actions/setup-node@v6 |
| 61 | + if: ${{ needs.release-please.outputs.release_created }} |
46 | 62 | with: |
47 | 63 | node-version: ${{ env.default_node_version }} |
48 | | - registry-url: https://registry.npmjs.org/ |
| 64 | + registry-url: ${{ env.registry_url }} |
49 | 65 |
|
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 }} |
51 | 68 |
|
52 | 69 | publish-ghp: |
53 | | - needs: build |
| 70 | + if: ${{ needs.release-please.outputs.release_created }} |
| 71 | + needs: release-please |
54 | 72 | runs-on: ubuntu-latest |
55 | | - env: |
56 | | - SCOPE: "@${{github.repository_owner}}" |
57 | 73 | permissions: |
58 | 74 | contents: read |
59 | 75 | packages: write |
60 | 76 | 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 |
61 | 83 | steps: |
62 | 84 | - uses: actions/checkout@v6 |
| 85 | + if: ${{ needs.release-please.outputs.release_created }} |
63 | 86 | with: |
64 | 87 | submodules: "recursive" |
65 | 88 |
|
| 89 | + - uses: actions/download-artifact@v8 |
| 90 | + if: ${{ needs.release-please.outputs.release_created }} |
| 91 | + with: |
| 92 | + name: ${{ env.artifact_name }} |
| 93 | + |
66 | 94 | - uses: actions/setup-node@v6 |
| 95 | + if: ${{ needs.release-please.outputs.release_created }} |
67 | 96 | with: |
68 | 97 | node-version: ${{ env.default_node_version }} |
69 | | - registry-url: "https://npm.pkg.github.com/" |
| 98 | + registry-url: ${{ env.registry_url }} |
70 | 99 | # 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 }} |
78 | 102 |
|
79 | 103 | - name: rename package name |
80 | 104 | run: | |
81 | 105 | node ./scripts/renamePackage.mjs |
82 | 106 |
|
83 | | - - run: npm publish --access public --registry=https://npm.pkg.github.com |
| 107 | + - run: npm publish --access public --registry=${{ env.registry_url }} |
84 | 108 | 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 }} |
0 commit comments