|
| 1 | +# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json |
| 2 | + |
| 3 | +name: Build and Publish |
| 4 | + |
| 5 | +on: |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - '*' |
| 9 | + tags: |
| 10 | + - 'v*' |
| 11 | + pull_request: |
| 12 | + branches: |
| 13 | + - main |
| 14 | + |
| 15 | +jobs: |
| 16 | + lint: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + name: Lint and typecheck |
| 19 | + |
| 20 | + steps: |
| 21 | + - name: Checkout repository |
| 22 | + uses: actions/checkout@v4 |
| 23 | + with: |
| 24 | + lfs: true |
| 25 | + |
| 26 | + - name: Setup Node.js with corepack |
| 27 | + uses: ./.github/actions/setup-node |
| 28 | + |
| 29 | + - name: Setup cache |
| 30 | + uses: ./.github/actions/setup-cache |
| 31 | + with: |
| 32 | + restore-key-prefix: 'lint-cache' |
| 33 | + |
| 34 | + - name: Install dependencies |
| 35 | + run: pnpm install --frozen-lockfile |
| 36 | + |
| 37 | + - name: Run typecheck |
| 38 | + run: pnpm run check-types |
| 39 | + |
| 40 | + - name: Run linting |
| 41 | + run: pnpm run lint |
| 42 | + |
| 43 | + test: |
| 44 | + name: Run tests |
| 45 | + strategy: |
| 46 | + fail-fast: false |
| 47 | + matrix: |
| 48 | + os: [macos-latest, ubuntu-latest, windows-latest] |
| 49 | + runs-on: ${{ matrix.os }} |
| 50 | + |
| 51 | + steps: |
| 52 | + - name: Checkout repository |
| 53 | + uses: actions/checkout@v4 |
| 54 | + with: |
| 55 | + lfs: true |
| 56 | + |
| 57 | + - name: Setup Node.js with corepack |
| 58 | + uses: ./.github/actions/setup-node |
| 59 | + |
| 60 | + - name: Setup cache |
| 61 | + uses: ./.github/actions/setup-cache |
| 62 | + with: |
| 63 | + restore-key-prefix: 'test-cache' |
| 64 | + |
| 65 | + - name: Install dependencies |
| 66 | + run: pnpm install --frozen-lockfile |
| 67 | + |
| 68 | + - name: Run tests (Linux) |
| 69 | + if: runner.os == 'Linux' |
| 70 | + run: xvfb-run -a pnpm run test |
| 71 | + |
| 72 | + - name: Run tests (non-Linux) |
| 73 | + if: runner.os != 'Linux' |
| 74 | + run: pnpm run test |
| 75 | + |
| 76 | + build: |
| 77 | + runs-on: ubuntu-latest |
| 78 | + name: Build extension |
| 79 | + |
| 80 | + steps: |
| 81 | + - name: Checkout repository |
| 82 | + uses: actions/checkout@v4 |
| 83 | + with: |
| 84 | + lfs: true |
| 85 | + |
| 86 | + - name: Setup Node.js with corepack |
| 87 | + uses: ./.github/actions/setup-node |
| 88 | + |
| 89 | + - name: Setup cache |
| 90 | + uses: ./.github/actions/setup-cache |
| 91 | + with: |
| 92 | + restore-key-prefix: 'build-cache' |
| 93 | + |
| 94 | + - name: Install dependencies |
| 95 | + run: pnpm install --frozen-lockfile |
| 96 | + |
| 97 | + - name: Build extension |
| 98 | + run: pnpm run package |
| 99 | + |
| 100 | + - name: Validate package version |
| 101 | + run: | |
| 102 | + PACKAGE_VERSION=$(jq -r '.version' package.json) |
| 103 | + MINOR_VERSION=$(echo "$PACKAGE_VERSION" | cut -d. -f2) |
| 104 | + if [ $((MINOR_VERSION % 2)) -ne 0 ]; then |
| 105 | + echo "Error: Minor version must be even. Current version: $PACKAGE_VERSION" |
| 106 | + echo "::error title=Minor version must be even::Minor version in package.json must be even. Current version: $PACKAGE_VERSION" |
| 107 | + exit 1 |
| 108 | + fi |
| 109 | + echo "Version validation passed: $PACKAGE_VERSION" |
| 110 | +
|
| 111 | + - name: Set version for packaging |
| 112 | + id: version |
| 113 | + run: | |
| 114 | + if [[ "${{ github.ref_type }}" == "tag" ]]; then |
| 115 | + PACKAGE_VERSION=$(jq -r '.version' package.json) |
| 116 | + VERSION="${PACKAGE_VERSION}" |
| 117 | + else |
| 118 | + PACKAGE_VERSION=$(jq -r '.version' package.json) |
| 119 | + MAJOR=$(echo "$PACKAGE_VERSION" | cut -d. -f1) |
| 120 | + MINOR=$(echo "$PACKAGE_VERSION" | cut -d. -f2) |
| 121 | + NEXT_MINOR=$((MINOR + 1)) |
| 122 | + # Use GitHub run number for guaranteed increment |
| 123 | + PATCH="${{ github.run_number }}" |
| 124 | + VERSION="${MAJOR}.${NEXT_MINOR}.${PATCH}" |
| 125 | + fi |
| 126 | + echo "version=${VERSION}" >> $GITHUB_OUTPUT |
| 127 | +
|
| 128 | + - name: Package extension (Pre-release) |
| 129 | + if: github.ref_type != 'tag' |
| 130 | + run: | |
| 131 | + # Temporarily update package.json version for pre-release packaging |
| 132 | + jq --arg version "${{ steps.version.outputs.version }}" '.version = $version' package.json > package.json.tmp |
| 133 | + mv package.json.tmp package.json |
| 134 | +
|
| 135 | + pnpm vsce package --no-dependencies --pre-release --out "package-navigator-${{ steps.version.outputs.version }}.vsix" |
| 136 | + echo "📦 Build type: Pre-release" >> $GITHUB_STEP_SUMMARY |
| 137 | + echo "🚀 Version: ${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY |
| 138 | +
|
| 139 | + - name: Package extension (Release) |
| 140 | + if: github.ref_type == 'tag' |
| 141 | + run: | |
| 142 | + pnpm vsce package --no-dependencies --out "package-navigator-${{ steps.version.outputs.version }}.vsix" |
| 143 | + echo "📦 Build type: Release" >> $GITHUB_STEP_SUMMARY |
| 144 | + echo "🚀 Version: ${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY |
| 145 | +
|
| 146 | + - name: Upload build artifacts |
| 147 | + uses: actions/upload-artifact@v4 |
| 148 | + with: |
| 149 | + name: vscode-extension |
| 150 | + path: '*.vsix' |
| 151 | + |
| 152 | + publish-ovsx: |
| 153 | + if: github.ref_type == 'tag' || (github.ref_type == 'branch' && github.ref == 'refs/heads/main') |
| 154 | + needs: |
| 155 | + - lint |
| 156 | + - test |
| 157 | + - build |
| 158 | + runs-on: ubuntu-latest |
| 159 | + name: Publish to Open VSX |
| 160 | + |
| 161 | + steps: |
| 162 | + - name: Setup Node.js |
| 163 | + uses: actions/setup-node@v4 |
| 164 | + with: |
| 165 | + node-version: 22 |
| 166 | + |
| 167 | + - name: Enable corepack |
| 168 | + shell: bash |
| 169 | + run: corepack enable |
| 170 | + |
| 171 | + - name: Prepare pnpm |
| 172 | + shell: bash |
| 173 | + run: | |
| 174 | + corepack prepare pnpm@latest --activate |
| 175 | + echo "PNPM_HOME=$HOME/.local/share/pnpm" >> $GITHUB_ENV |
| 176 | + echo "$HOME/.local/share/pnpm" >> $GITHUB_PATH |
| 177 | +
|
| 178 | + - name: Install ovsx CLI |
| 179 | + run: pnpm add -g ovsx --dangerously-allow-all-builds |
| 180 | + |
| 181 | + - name: Download build artifacts |
| 182 | + uses: actions/download-artifact@v4 |
| 183 | + with: |
| 184 | + name: vscode-extension |
| 185 | + |
| 186 | + - name: Publish to Open VSX |
| 187 | + run: ovsx publish --packagePath *.vsix --pat ${{ secrets.OVSX_TOKEN }} |
| 188 | + |
| 189 | + publish-vsce: |
| 190 | + if: github.ref_type == 'tag' || (github.ref_type == 'branch' && github.ref == 'refs/heads/main') |
| 191 | + needs: |
| 192 | + - lint |
| 193 | + - test |
| 194 | + - build |
| 195 | + runs-on: ubuntu-latest |
| 196 | + name: Publish to VS Code Marketplace |
| 197 | + |
| 198 | + steps: |
| 199 | + - name: Setup Node.js |
| 200 | + uses: actions/setup-node@v4 |
| 201 | + with: |
| 202 | + node-version: 22 |
| 203 | + |
| 204 | + - name: Enable corepack |
| 205 | + shell: bash |
| 206 | + run: corepack enable |
| 207 | + |
| 208 | + - name: Prepare pnpm |
| 209 | + shell: bash |
| 210 | + run: | |
| 211 | + corepack prepare pnpm@latest --activate |
| 212 | + echo "PNPM_HOME=$HOME/.local/share/pnpm" >> $GITHUB_ENV |
| 213 | + echo "$HOME/.local/share/pnpm" >> $GITHUB_PATH |
| 214 | +
|
| 215 | + - name: Install vsce CLI |
| 216 | + run: pnpm add -g vsce --dangerously-allow-all-builds |
| 217 | + |
| 218 | + - name: Download build artifacts |
| 219 | + uses: actions/download-artifact@v4 |
| 220 | + with: |
| 221 | + name: vscode-extension |
| 222 | + |
| 223 | + - name: Publish to VS Code Marketplace |
| 224 | + run: vsce publish --packagePath *.vsix --pat ${{ secrets.VSCE_TOKEN }} |
0 commit comments