Ensure deployment only runs from main
#54
This file contains 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
name: Build and Publish VS Code Extension | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
workflow_dispatch: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 'latest' | |
cache: 'npm' | |
- name: Save the short SHA of the commit | |
run: echo "SHORT_SHA=$(echo ${GITHUB_SHA} | head -c 7)" >> $GITHUB_ENV | |
# Check and build the extension | |
- run: npm ci | |
- run: mkdir libs | |
- run: curl https://gradle.github.io/declarative-lsp/lsp-all.jar -o libs/lsp-all.jar | |
- run: npm run check | |
- run: npm run lint | |
- run: npm run build | |
# Rolling the VSIX package | |
- run: npm install @vscode/vsce | |
- run: npx vsce package --pre-release --out site/declarative-gradle-support-${SHORT_SHA}.vsix | |
# Prepping and uploading the Pages site artifact | |
- name: Template site.html | |
run: sed -i "s/{{SHORT_SHA}}/${SHORT_SHA}/g" site/index.html | |
- uses: actions/upload-pages-artifact@v3 | |
with: | |
path: site/ | |
deploy-pages: | |
if: github.ref == 'refs/heads/main' | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
pages: write | |
id-token: write | |
environment: | |
name: github-pages | |
url: ${{steps.deployment.outputs.page_url}} | |
needs: | |
- build | |
steps: | |
- uses: actions/deploy-pages@v4 |