add commands #25
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-deploy | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build-and-deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@v1 | |
with: | |
node-version: '20' | |
- name: Set release number to package | |
run: sed -i 's|@VERSION_FROM_RUNNER@|${{ github.run_number}}|' package.json | |
- name: Install Dependencies | |
run: npm install | |
- name: Install VSCE | |
run: npm install -g vsce | |
- name: Package Extension | |
run: vsce package | |
- name: Publish Extension | |
run: vsce publish | |
env: | |
VSCE_PAT: ${{ secrets.VSCE_PAT }} | |
steps: | |
- name: Generate release notes | |
uses: actions/github-script@v7 | |
id: release_notes | |
with: | |
result-encoding: string | |
script: | | |
const { owner, repo } = context.repo; | |
const tagName = context.payload.ref.replace('refs/tags/', ''); | |
const listReleases = await github.rest.repos.listReleases({ owner, repo }); | |
const thisRelease = listReleases.data.find(release => release.tag_name === tagName); | |
let previousRelease = listReleases.data[0]; | |
if (thisRelease) { | |
const thisIndex = listReleases.data.findIndex(release => release.id === thisRelease.id); | |
previousRelease = listReleases.data[thisIndex + 1]; | |
} | |
const comparison = await github.rest.repos.compareCommits({ | |
owner, | |
repo, | |
base: previousRelease.tag_name, | |
head: tagName, | |
}); | |
const pullRequests = comparison.data.commits | |
.map(commit => { | |
const match = commit.commit.message.match(/Merge pull request #(\d+)/); | |
return match ? match[1] : null; | |
}) | |
.filter(Boolean); | |
const releaseNotes = pullRequests.map(prNumber => `- PR #${prNumber}`).join('\n'); | |
core.setOutput('release_notes', releaseNotes); | |
return releaseNotes; | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Create Release | |
id: create_release | |
uses: actions/create-release@v1.1.4 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ github.run_number }} | |
release_name: Release 1.0.${{ github.run_number }} | |
body: ${{ steps.release_notes.outputs.result }} | |
draft: false | |
prerelease: false |