microsoft/hve-core
Publicmirrored fromhttps://github.com/microsoft/hve-coreAvailable
.github/workflows/extension-publish.yml
159lines · modecode
| 1 | name: Publish Extension |
| 2 | |
| 3 | on: |
| 4 | # Release trigger disabled - extension publishing is manual-only |
| 5 | # Uncomment to enable auto-publish on GitHub releases: |
| 6 | # release: |
| 7 | # types: [published] |
| 8 | workflow_dispatch: |
| 9 | inputs: |
| 10 | version: |
| 11 | description: 'Version to publish (leave empty to auto-detect from latest release)' |
| 12 | required: false |
| 13 | type: string |
| 14 | default: '' |
| 15 | dry-run: |
| 16 | description: 'Dry run (package only, do not publish)' |
| 17 | required: false |
| 18 | type: boolean |
| 19 | default: false |
| 20 | |
| 21 | permissions: |
| 22 | contents: read |
| 23 | |
| 24 | jobs: |
| 25 | prepare-changelog: |
| 26 | name: Prepare Changelog |
| 27 | runs-on: ubuntu-latest |
| 28 | outputs: |
| 29 | changelog-path: ${{ steps.create-changelog.outputs.path }} |
| 30 | steps: |
| 31 | - name: Checkout code |
| 32 | uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v4.2.2 |
| 33 | with: |
| 34 | persist-credentials: false |
| 35 | |
| 36 | - name: Create changelog file |
| 37 | id: create-changelog |
| 38 | run: | |
| 39 | if [ "${{ github.event_name }}" == "release" ]; then |
| 40 | cat > CHANGELOG.md << 'EOF' |
| 41 | ${{ github.event.release.body }} |
| 42 | EOF |
| 43 | echo "path=CHANGELOG.md" >> "$GITHUB_OUTPUT" |
| 44 | elif [ "${{ github.event_name }}" == "workflow_dispatch" ]; then |
| 45 | echo "path=" >> "$GITHUB_OUTPUT" |
| 46 | else |
| 47 | echo "path=" >> "$GITHUB_OUTPUT" |
| 48 | fi |
| 49 | |
| 50 | - name: Upload changelog |
| 51 | if: steps.create-changelog.outputs.path != '' |
| 52 | uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v4.4.3 |
| 53 | with: |
| 54 | name: changelog |
| 55 | path: CHANGELOG.md |
| 56 | retention-days: 1 |
| 57 | |
| 58 | normalize-version: |
| 59 | name: Normalize Version |
| 60 | runs-on: ubuntu-latest |
| 61 | outputs: |
| 62 | version: ${{ steps.normalize.outputs.version }} |
| 63 | steps: |
| 64 | - name: Normalize version string |
| 65 | id: normalize |
| 66 | env: |
| 67 | GH_TOKEN: ${{ github.token }} |
| 68 | run: | |
| 69 | if [ "${{ github.event_name }}" == "release" ]; then |
| 70 | VERSION="${{ github.event.release.tag_name }}" |
| 71 | else |
| 72 | VERSION="${{ inputs.version }}" |
| 73 | fi |
| 74 | # Strip leading 'v' and component prefix if present |
| 75 | VERSION="${VERSION#v}" |
| 76 | VERSION="${VERSION#hve-core-v}" |
| 77 | |
| 78 | # Auto-detect from latest release tag when no version specified |
| 79 | if [ -z "$VERSION" ]; then |
| 80 | TAG=$(gh release view --json tagName -q '.tagName' -R "${{ github.repository }}") |
| 81 | VERSION="${TAG#hve-core-v}" |
| 82 | echo "📦 Auto-detected version from latest release: $VERSION" |
| 83 | fi |
| 84 | |
| 85 | echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 86 | |
| 87 | package: |
| 88 | name: Package Extensions |
| 89 | needs: [prepare-changelog, normalize-version] |
| 90 | uses: ./.github/workflows/extension-package.yml |
| 91 | with: |
| 92 | version: ${{ needs.normalize-version.outputs.version }} |
| 93 | use-changelog: ${{ needs.prepare-changelog.outputs.changelog-path != '' }} |
| 94 | permissions: |
| 95 | contents: read |
| 96 | |
| 97 | publish: |
| 98 | name: Publish ${{ matrix.id }} |
| 99 | needs: [package] |
| 100 | if: ${{ !inputs.dry-run }} |
| 101 | runs-on: ubuntu-latest |
| 102 | environment: marketplace |
| 103 | strategy: |
| 104 | fail-fast: false |
| 105 | matrix: ${{ fromJson(needs.package.outputs.collections-matrix) }} |
| 106 | permissions: |
| 107 | contents: read |
| 108 | id-token: write |
| 109 | steps: |
| 110 | - name: Checkout code |
| 111 | uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v4.2.2 |
| 112 | with: |
| 113 | persist-credentials: false |
| 114 | |
| 115 | - name: Azure Login (OIDC) |
| 116 | uses: azure/login@a457da9ea143d694b1b9c7c869ebb04ebe844ef5 # v2.3.0 |
| 117 | with: |
| 118 | client-id: ${{ secrets.AZURE_CLIENT_ID }} |
| 119 | tenant-id: ${{ secrets.AZURE_TENANT_ID }} |
| 120 | subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} |
| 121 | |
| 122 | - name: Setup Node.js |
| 123 | uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v4.1.0 |
| 124 | with: |
| 125 | node-version: '20' |
| 126 | |
| 127 | - name: Install VSCE |
| 128 | run: npm install -g @vscode/vsce@3.7.1 |
| 129 | |
| 130 | - name: Download VSIX artifact |
| 131 | uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0 |
| 132 | with: |
| 133 | name: extension-vsix-${{ matrix.id }} |
| 134 | path: ./dist |
| 135 | |
| 136 | - name: Publish to VS Code Marketplace |
| 137 | id: publish |
| 138 | run: | |
| 139 | VSIX_FILE=$(find dist -name '*.vsix' -printf '%T@ %p\n' | sort -rn | head -1 | cut -d' ' -f2) |
| 140 | if [ -z "$VSIX_FILE" ]; then |
| 141 | echo "::error::No VSIX file found for collection ${{ matrix.id }}" |
| 142 | exit 1 |
| 143 | fi |
| 144 | # Extract version from VSIX filename to avoid depending on matrix job output |
| 145 | VSIX_VERSION=$(basename "$VSIX_FILE" .vsix | grep -oE '[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?$') |
| 146 | echo "version=$VSIX_VERSION" >> "$GITHUB_OUTPUT" |
| 147 | echo "📦 Publishing ${{ matrix.id }}: $VSIX_FILE (v$VSIX_VERSION)" |
| 148 | vsce publish --packagePath "$VSIX_FILE" --azure-credential |
| 149 | |
| 150 | - name: Summary |
| 151 | run: | |
| 152 | { |
| 153 | echo "## 🎉 Extension Published: ${{ matrix.name }}" |
| 154 | echo "" |
| 155 | echo "**Collection:** ${{ matrix.id }}" |
| 156 | echo "**Version:** ${{ steps.publish.outputs.version }}" |
| 157 | echo "" |
| 158 | echo "View on [VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=ise-hve-essentials.${{ matrix.name }})" |
| 159 | } >> "$GITHUB_STEP_SUMMARY" |
| 160 | |