Split release/publish workflos
This commit is contained in:
@@ -1,45 +0,0 @@
|
||||
name: Publish npm packages
|
||||
|
||||
on:
|
||||
# For now auto-publish every change to the default branch
|
||||
push:
|
||||
branches: [main]
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
bump:
|
||||
description: How to increase the version
|
||||
type: choice
|
||||
default: patch
|
||||
options:
|
||||
- patch
|
||||
- minor
|
||||
- major
|
||||
version:
|
||||
description: The version to publish
|
||||
type: string
|
||||
default: ''
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 16
|
||||
registry-url: 'https://npm.pkg.github.com'
|
||||
scope: '@actions'
|
||||
|
||||
- run: npm ci
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- run: |
|
||||
git config user.name github-actions
|
||||
git config user.email [email protected]
|
||||
|
||||
- name: Publish packages
|
||||
run: npx lerna publish ${{ inputs.version || inputs.bump || 'patch' }} --yes
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -0,0 +1,51 @@
|
||||
name: Create release PR
|
||||
|
||||
run-name: Create release PR for v${{ github.event.inputs.version }}
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
version:
|
||||
required: true
|
||||
description: "Version to bump `package.json` to (format: x.y.z)"
|
||||
|
||||
jobs:
|
||||
create-release-pr:
|
||||
name: Create release PR
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: "16"
|
||||
|
||||
- name: Bump version and push
|
||||
run: |
|
||||
git config --global user.email "[email protected]"
|
||||
git config --global user.name "GitHub Actions"
|
||||
|
||||
git checkout -b release/${{ inputs.version }}
|
||||
|
||||
npx lerna version ${{ inputs.version }} --yes --no-push --no-git-tag-version
|
||||
|
||||
git add package.json package-lock.json
|
||||
git commit -m "Release extension version ${{ inputs.version }}"
|
||||
|
||||
git push --set-upstream origin release/${{ inputs.version }}
|
||||
|
||||
- name: Create PR
|
||||
run: |
|
||||
gh pr create \
|
||||
--title "Release version ${{ inputs.version }}" \
|
||||
--body "Release version ${{ inputs.version }}" \
|
||||
--base main \
|
||||
--head release/${{ inputs.version }}
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -0,0 +1,106 @@
|
||||
name: Release and publish extension
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- package.json
|
||||
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
version:
|
||||
description: "Version to release"
|
||||
required: true
|
||||
|
||||
jobs:
|
||||
check-version-change:
|
||||
outputs:
|
||||
changed: ${{ steps.check-version.outputs.result }}
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Check if version has changed
|
||||
id: check-version
|
||||
uses: actions/github-script@v6
|
||||
with:
|
||||
script: |
|
||||
const version = '${{ inputs.version }}' || require('./package.json').version;
|
||||
// Find a release for that version
|
||||
const release = await github.rest.repos.getReleaseByTag({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
tag: `release-v${version}`,
|
||||
}).catch(() => null);
|
||||
|
||||
// If the release exists, the version has not changed
|
||||
if (release) {
|
||||
console.log(`Version ${version} has an existing release`);
|
||||
console.log(release.data.html_url);
|
||||
core.summary.addLink(`Release v${version}`, release.data.html_url);
|
||||
await core.summary.write();
|
||||
return "false";
|
||||
}
|
||||
console.log(`Version ${version} does not have a release`);
|
||||
return true;
|
||||
|
||||
release:
|
||||
environment: publish
|
||||
|
||||
needs: check-version-change
|
||||
if: ${{ needs.check-version-change.outputs.changed == 'true' }}
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
env:
|
||||
EXT_VERSION: "" # will be set in the workflow
|
||||
|
||||
outputs:
|
||||
version: ${{ env.EXT_VERSION }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 16.x
|
||||
cache: "npm"
|
||||
registry-url: "https://npm.pkg.github.com"
|
||||
|
||||
- name: Parse version from package.json
|
||||
run: |
|
||||
echo "EXT_VERSION=$(node -p -e "require('./package.json').version")" >> $GITHUB_ENV
|
||||
|
||||
- run: npm ci
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Publish packages
|
||||
run: |
|
||||
lerna publish from-git
|
||||
|
||||
- name: Create release and upload release asset
|
||||
uses: actions/github-script@v6
|
||||
with:
|
||||
script: |
|
||||
const fs = require("fs");
|
||||
|
||||
const release = await github.rest.repos.createRelease({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
tag_name: "release-v${{ env.EXT_VERSION }}",
|
||||
name: "v${{ env.EXT_VERSION }}",
|
||||
draft: false,
|
||||
prerelease: false
|
||||
});
|
||||
|
||||
core.summary.addLink(`Release v${{ env.EXT_VERSION }}`, release.data.html_url);
|
||||
await core.summary.write();
|
||||
Reference in New Issue
Block a user