Merge branch 'main' into fix/reusable-prerelease-npm-token-gating-202… #9
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## | ||
|
Check failure on line 1 in .github/workflows/reusable-prerelease.yml
|
||
| # Reusable Pre-Release Workflow | ||
| # | ||
| # Centralized prerelease workflow for all winccoa-tools-pack repositories. | ||
| # Handles both VS Code extension (VSIX) and npm library (tarball) projects. | ||
| # | ||
| # Secret resolution (handled by GitHub automatically): | ||
| # 1. Repository-level secret (user-defined per repo - highest priority) | ||
| # 2. Organization-level secret (shared fallback for the whole org) | ||
| # Callers just use `secrets: inherit` - GitHub resolves the priority. | ||
| # | ||
| # Usage (VS Code extension - caller: pre-release.yml or pre-release-develop.yml): | ||
| # jobs: | ||
| # pre-release: | ||
| # uses: winccoa-tools-pack/.github/.github/workflows/reusable-prerelease.yml@main | ||
| # with: | ||
| # target_branch: ${{ github.head_ref || github.ref_name }} | ||
| # project_type: vscode | ||
| # secrets: inherit | ||
| # | ||
| # Usage (npm library): | ||
| # jobs: | ||
| # pre-release: | ||
| # uses: winccoa-tools-pack/.github/.github/workflows/reusable-prerelease.yml@main | ||
| # with: | ||
| # target_branch: ${{ github.head_ref || github.ref_name }} | ||
| # project_type: npm | ||
| # publish_to_npm: false | ||
| # secrets: inherit | ||
| ## | ||
| name: "Reusable: Pre-Release" | ||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| target_branch: | ||
| description: "Branch that triggered prerelease (e.g. release/v1.2.3 or develop)" | ||
| required: true | ||
| type: string | ||
| validate_release_branch: | ||
| description: "If true: require target_branch to be release/vX.Y.Z and match the computed version" | ||
| required: false | ||
| default: true | ||
| type: boolean | ||
| project_type: | ||
| description: "Project type: 'vscode' for VS Code extensions (VSIX), 'npm' for npm libraries (tarball)" | ||
| required: true | ||
| type: string | ||
| publish_to_npm: | ||
| description: "If true and project_type=npm: publish to npm with 'next' dist-tag. Ignored for vscode projects." | ||
| required: false | ||
| default: false | ||
| type: boolean | ||
| secrets: | ||
| NPM_TOKEN: | ||
| description: "npm token for publishing (required only if publish_to_npm is true)" | ||
| required: false | ||
| outputs: | ||
| version: | ||
| description: "Computed prerelease version (x.y.z-<shortsha>)" | ||
| value: ${{ jobs.prerelease.outputs.version }} | ||
| tag: | ||
| description: "Computed prerelease tag (v<version>)" | ||
| value: ${{ jobs.prerelease.outputs.tag }} | ||
| permissions: | ||
| contents: write | ||
| concurrency: | ||
| group: release-pipeline-${{ github.repository }} | ||
| cancel-in-progress: false | ||
| jobs: | ||
| # -------------------------------------------- | ||
| # Versioning (shared - delegates to existing reusable) | ||
| # -------------------------------------------- | ||
| versioning: | ||
| uses: winccoa-tools-pack/.github/.github/workflows/versioning-tags-changelog-reusable.yml@main | ||
| with: | ||
| mode: prerelease | ||
| target_branch: ${{ inputs.target_branch }} | ||
| validate_release_branch: ${{ inputs.validate_release_branch }} | ||
| push_tag: true | ||
| force_push_tag: true | ||
| secrets: inherit | ||
| # -------------------------------------------- | ||
| # Build & publish prerelease | ||
| # -------------------------------------------- | ||
| prerelease: | ||
| runs-on: ubuntu-latest | ||
| needs: [versioning] | ||
| outputs: | ||
| version: ${{ steps.meta.outputs.version }} | ||
| tag: ${{ steps.meta.outputs.tag }} | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| fetch-depth: 0 | ||
| ref: ${{ inputs.target_branch != '' && inputs.target_branch || github.sha }} | ||
| - name: Use Node.js 20.x | ||
| uses: actions/setup-node@v6 | ||
| with: | ||
| node-version: 20.x | ||
| cache: "npm" | ||
| # npm registry config needed for npm projects | ||
| registry-url: ${{ inputs.project_type == 'npm' && 'https://registry.npmjs.org' || '' }} | ||
| scope: ${{ inputs.project_type == 'npm' && '@winccoa-tools-pack' || '' }} | ||
| - name: Install dependencies | ||
| run: npm ci | ||
| # -- VS Code: install vsce -- | ||
| - name: Install vsce | ||
| if: ${{ inputs.project_type == 'vscode' }} | ||
| run: npm install -g @vscode/vsce | ||
| - name: Set prerelease metadata | ||
| id: meta | ||
| shell: bash | ||
| run: | | ||
| TAG="${{ needs.versioning.outputs.tag }}" | ||
| VERSION="${TAG#v}" | ||
| echo "tag=$TAG" >> "$GITHUB_OUTPUT" | ||
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | ||
| # -- npm: update package.json version -- | ||
| - name: Set package.json version | ||
| if: ${{ inputs.project_type == 'npm' }} | ||
| shell: bash | ||
| run: npm pkg set version="${{ steps.meta.outputs.version }}" | ||
| # -- Release body -- | ||
| - name: Build release body (vscode) | ||
| if: ${{ inputs.project_type == 'vscode' }} | ||
| id: body-vscode | ||
| shell: bash | ||
| run: | | ||
| { | ||
| echo "body<<EOF" | ||
| echo "${{ needs.versioning.outputs.changelog }}" | ||
| echo "" | ||
| echo "### Testing Notes" | ||
| echo "- This is a **pre-release** build; download the attached VSIX and test locally" | ||
| echo "- Source branch: ${{ inputs.target_branch }}" | ||
| echo "- Report issues at: https://github.com/${{ github.repository }}/issues" | ||
| echo "EOF" | ||
| } >> "$GITHUB_OUTPUT" | ||
| - name: Build release body (npm) | ||
| if: ${{ inputs.project_type == 'npm' }} | ||
| id: body-npm | ||
| shell: bash | ||
| run: | | ||
| PACKAGE_NAME=$(jq -r '.name' package.json) | ||
| { | ||
| echo "body<<EOF" | ||
| echo "${{ needs.versioning.outputs.changelog }}" | ||
| echo "" | ||
| echo "### Testing Notes" | ||
| echo "- This is a **pre-release** npm package published with dist-tag **next**" | ||
| echo "- Install: npm i $PACKAGE_NAME@${{ steps.meta.outputs.version }}" | ||
| echo "- Or: npm i $PACKAGE_NAME@next" | ||
| echo "- Source branch: ${{ inputs.target_branch }}" | ||
| echo "- Report issues at: https://github.com/${{ github.repository }}/issues" | ||
| echo "EOF" | ||
| } >> "$GITHUB_OUTPUT" | ||
| # -- VS Code: package VSIX -- | ||
| - name: Package extension (VSIX) | ||
| if: ${{ inputs.project_type == 'vscode' }} | ||
| run: vsce package | ||
| # -- npm: build & pack tarball -- | ||
| - name: Build package | ||
| if: ${{ inputs.project_type == 'npm' }} | ||
| run: npm run build | ||
| - name: Create tarball (npm pack) | ||
| if: ${{ inputs.project_type == 'npm' }} | ||
| run: npm pack | ||
| - name: "Publish to npm (dist-tag: next)" | ||
| if: ${{ inputs.project_type == 'npm' && inputs.publish_to_npm && github.repository_owner == 'winccoa-tools-pack' && secrets.NPM_TOKEN != '' }} | ||
| env: | ||
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
| run: npm publish --tag next --access public --ignore-scripts | ||
| - name: "Skip npm publish (no token available)" | ||
| if: ${{ inputs.project_type == 'npm' && inputs.publish_to_npm && github.repository_owner == 'winccoa-tools-pack' && secrets.NPM_TOKEN == '' }} | ||
| run: | | ||
| echo "Skipping npm publish: NPM_TOKEN is not available in this workflow run (e.g. Dependabot PR)." | ||
| # -- Upload artifact -- | ||
| - name: Upload VSIX artifact | ||
| if: ${{ inputs.project_type == 'vscode' }} | ||
| uses: actions/upload-artifact@v6 | ||
| with: | ||
| name: ${{ format('pre-release-{0}', github.sha) }} | ||
| path: "*.vsix" | ||
| retention-days: 14 | ||
| - name: Upload npm tarball artifact | ||
| if: ${{ inputs.project_type == 'npm' }} | ||
| uses: actions/upload-artifact@v7 | ||
| with: | ||
| name: ${{ format('pre-release-{0}', github.sha) }} | ||
| path: "*.tgz" | ||
| retention-days: 14 | ||
| # -- GitHub prerelease -- | ||
| - name: Create GitHub prerelease | ||
| uses: softprops/action-gh-release@v2 | ||
| with: | ||
| tag_name: ${{ steps.meta.outputs.tag }} | ||
| name: ${{ format('Pre-Release {0}', steps.meta.outputs.tag) }} | ||
| target_commitish: ${{ inputs.target_branch != '' && inputs.target_branch || github.sha }} | ||
| body: ${{ inputs.project_type == 'vscode' && steps.body-vscode.outputs.body || steps.body-npm.outputs.body }} | ||
| files: ${{ inputs.project_type == 'vscode' && '*.vsix' || '*.tgz' }} | ||
| draft: false | ||
| prerelease: true | ||
| generate_release_notes: true | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||