|
| 1 | +name: Node.js Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + secrets: |
| 6 | + NPM_TOKEN: |
| 7 | + description: 'npm token' |
| 8 | + required: true |
| 9 | + GIT_TOKEN: |
| 10 | + description: 'github personal token' |
| 11 | + required: true |
| 12 | + |
| 13 | + inputs: |
| 14 | + checkTest: |
| 15 | + type: boolean |
| 16 | + description: whether run test before release |
| 17 | + default: false |
| 18 | + |
| 19 | + dryRun: |
| 20 | + type: boolean |
| 21 | + description: pass dry-run to semantic-release |
| 22 | + default: false |
| 23 | + |
| 24 | + install: |
| 25 | + type: string |
| 26 | + description: 'Install dependencies script' |
| 27 | + default: 'npm i --no-package-lock --no-fund' |
| 28 | + |
| 29 | + action_ref: |
| 30 | + type: string |
| 31 | + description: 'Branch name for node-modules/github-actions, for test purpose' |
| 32 | + default: master |
| 33 | + |
| 34 | +jobs: |
| 35 | + Release: |
| 36 | + permissions: |
| 37 | + contents: write |
| 38 | + deployments: write |
| 39 | + runs-on: ubuntu-latest |
| 40 | + defaults: |
| 41 | + run: |
| 42 | + working-directory: main_repo |
| 43 | + |
| 44 | + concurrency: |
| 45 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 46 | + cancel-in-progress: true |
| 47 | + |
| 48 | + steps: |
| 49 | + # Checkout action repository |
| 50 | + - name: Checkout action repository |
| 51 | + uses: actions/checkout@v4 |
| 52 | + with: |
| 53 | + repository: node-modules/github-actions |
| 54 | + path: action_repo |
| 55 | + ref: ${{ inputs.action_ref }} |
| 56 | + |
| 57 | + # Checkout project repository |
| 58 | + - name: Checkout project repository |
| 59 | + uses: actions/checkout@v4 |
| 60 | + with: |
| 61 | + path: main_repo |
| 62 | + token: ${{ secrets.GIT_TOKEN }} |
| 63 | + |
| 64 | + # Setup Node.js environment |
| 65 | + - name: Setup Node.js |
| 66 | + uses: actions/setup-node@v4 |
| 67 | + |
| 68 | + # Install action dependencies |
| 69 | + - name: Install action dependencies |
| 70 | + run: npm i --no-package-lock --no-fund --omit=dev |
| 71 | + working-directory: action_repo/scripts/release |
| 72 | + |
| 73 | + # Install dependencies |
| 74 | + - name: Install dependencies |
| 75 | + run: ${{ inputs.install }} |
| 76 | + |
| 77 | + # Run Test Only |
| 78 | + - name: Run Test |
| 79 | + run: npm test |
| 80 | + if: inputs.checkTest |
| 81 | + |
| 82 | + - name: Semantic Release |
| 83 | + id: release |
| 84 | + run: node ../action_repo/scripts/release/index.js |
| 85 | + env: |
| 86 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 87 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 88 | + DRYRUN: ${{ inputs.dryRun }} |
| 89 | + |
| 90 | + - name: Publish ${{ steps.release.outputs.name }}@${{ steps.release.outputs.release_version }} |
| 91 | + if: steps.release.outputs.release_version && !inputs.dryRun |
| 92 | + run: | |
| 93 | + echo ${{ steps.release.outputs.name }} |
| 94 | + echo ${{ steps.release.outputs.release_version }} |
| 95 | + echo ${{ steps.release.outputs.registry }} |
| 96 | + echo ${{ steps.release.outputs.cnpm_sync_url }} |
0 commit comments