Skip to content

Publish

Publish #6

Workflow file for this run

name: Publish
on:
workflow_dispatch:
inputs:
releaseType:
description: "Release Type"
required: true
type: choice
default: "patch"
options:
- patch
- minor
- major
releaseChannel:
description: "Release Channel"
required: true
type: choice
default: stable
options:
- stable
- edge
publishMarketplace:
description: "Publish on Visual Studio Marketplace?"
required: true
type: choice
default: "yes"
options:
- "yes"
- "no"
jobs:
release:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
pull-requests: write
steps:
- name: Check for correct branch (Edge)
if: github.event.inputs.releaseChannel == 'edge'
run: |
if [ "$GITHUB_REF_NAME" = "edge" ]; then
echo "Correct branch was used, proceeding with edge release"
else
echo "The 'edge' release must come from a branch called 'edge'"
echo "(it was: '${GITHUB_REF_NAME}')"
exit 1
fi;
- name: Check for correct branch (Stable)
if: github.event.inputs.releaseChannel == 'stable'
run: |
if [ "$GITHUB_REF_NAME" = "main" ]; then
echo "Correct branch was used, proceeding with stable release"
else
echo "The 'stable' release must come from a branch called 'main'"
echo "(it was: '${GITHUB_REF_NAME}')"
exit 1
fi;
- name: Clone Repository
uses: actions/checkout@dc323e67f16fb5f7663d20ff7941f27f5809e9b6 # pin@v2
with:
fetch-depth: 0
- name: Setup Node version
uses: actions/setup-node@f1f314fca9dfce2769ece7d933488f076716723e # pin@v1
with:
node-version: 19
- name: Install vsce globally
run: npm install -g @vscode/vsce
- name: Install dependencies
run: npm install
- name: Build Package
run: npm run compile
- name: Create Changelog
run: |
git log $(git describe --tags --abbrev=0)..HEAD --oneline &> ${{ github.workspace }}-CHANGELOG.txt
cat ${{ github.workspace }}-CHANGELOG.txt
- name: Setup Git
run: |
git config --global user.name "ocm-release-bot"
git config --global user.email "[email protected]"
- name: Get Current Version Number
run: |
CURRENT_VERSION=$(cat package.json | jq .version | cut -d'"' -f 2)
echo "CURRENT_VERSION=$CURRENT_VERSION" >> $GITHUB_ENV
- name: Compile New Version (Edge)
run: |
RELEASE_VERSION=$(npx semver $CURRENT_VERSION -i pre${{ github.event.inputs.releaseType }} --preid edge)
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV
echo "Bump to $RELEASE_VERSION"
if: ${{ github.event.inputs.releaseChannel == 'edge' && !contains(env.CURRENT_VERSION, 'edge') }}
- name: Compile New Version (Edge)
run: |
RELEASE_VERSION=$(npx semver $CURRENT_VERSION -i prerelease)
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV
echo "Bump to $RELEASE_VERSION"
if: ${{ github.event.inputs.releaseChannel == 'edge' && contains(env.CURRENT_VERSION, 'edge') }}
- name: Compile New Version (Stable)
run: |
RELEASE_VERSION=$(npx semver $CURRENT_VERSION -i ${{ github.event.inputs.releaseType }})
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV
echo "Bump to $RELEASE_VERSION"
if: ${{ github.event.inputs.releaseChannel == 'stable' }}
- uses: chainguard-dev/actions/setup-gitsign@main
- name: Version Package
run: |
git status
git diff && git diff --cached
npm version $RELEASE_VERSION
git tag -a $RELEASE_VERSION -m "$RELEASE_VERSION"
- name: Package Extension (Edge)
if: ${{ github.event.inputs.releaseChannel == 'edge' }}
run: |
node .github/scripts/updateEdgeVersion.js
vsce package --pre-release --no-git-tag-version --no-update-package-json -o "./ocm-tools-$RELEASE_VERSION.vsix" ${{ github.event.inputs.additionalFlags }}
- name: Package Extension (Stable)
run: vsce package $RELEASE_VERSION --no-git-tag-version --no-update-package-json -o "./ocm-tools-$RELEASE_VERSION.vsix" ${{ github.event.inputs.additionalFlags }}
if: ${{ github.event.inputs.releaseChannel == 'stable' }}
- name: Publish to Visual Studio Marketplace (Edge)
run: vsce publish --packagePath "./ocm-tools-$RELEASE_VERSION.vsix" --pre-release --no-git-tag-version --no-update-package-json -p ${{ secrets.VSC_MKTP_PAT }} ${{ github.event.inputs.additionalFlags }}
if: ${{ github.event.inputs.publishMarketplace == 'yes' && github.event.inputs.releaseChannel == 'edge' }}
- name: Publish to Visual Studio Marketplace (Stable)
run: vsce publish --packagePath "./ocm-tools-$RELEASE_VERSION.vsix" --no-git-tag-version --no-update-package-json -p ${{ secrets.VSC_MKTP_PAT }} ${{ github.event.inputs.additionalFlags }}
if: ${{ github.event.inputs.publishMarketplace == 'yes' && github.event.inputs.releaseChannel == 'stable' }}
- name: Push Tags (Edge)
if: ${{ github.event.inputs.releaseChannel == 'edge' }}
run: |
git log -1 --stat
git push origin --force-with-lease edge:release-pr --tags
- name: Push Tags (Stable)
if: ${{ github.event.inputs.releaseChannel == 'stable' }}
run: |
git log -1 --stat
git push origin --force-with-lease main:release-pr --tags
- run: |
export GIT_TAG=$(git describe --tags --abbrev=0)
echo "GIT_TAG=$GIT_TAG" >> $GITHUB_ENV
- name: GitHub Release
uses: ncipollo/release-action@a2e71bdd4e7dab70ca26a852f29600c98b33153e # pin@v1
with:
artifacts: "./ocm-tools-*"
bodyFile: ${{ github.workspace }}-CHANGELOG.txt
tag: ${{ env.GIT_TAG }}
prerelease: ${{ github.event.inputs.releaseChannel == 'edge' }}
# We need to use a pull request because we need tags to be included in the history of our main
# branch. We don't want to make an exception for our "no pushes without a pull request" security
# policy, even for some robot. So just merge this PR manually to complete each release, or do a
# fast-forward of the edge branch catching it up to the `release-pr` branch, as it won't get the
# PR. (If you have trouble publishing more than one edge release, this mistake is usually why.)
- uses: repo-sync/pull-request@7e79a9f5dc3ad0ce53138f01df2fad14a04831c5 # pin@v2
name: Finish Release PR
if: ${{ github.event.inputs.releaseChannel != 'edge' }}
with:
source_branch: "release-pr"
destination_branch: "main"
pr_title: "Release ${{ env.GIT_TAG }}"
pr_body: |-
A release has been tagged and published, ${{ env.GIT_TAG }}! 🎉
Please ensure that \`CHANGELOG.md\` remains current by pushing any needed updates as a commit to this branch.
A CHANGELOG has been generated for this release here, [\`v${{ env.GIT_TAG }}\`](https://github.com/open-component-model/vscode-ocm-tools/releases/tag/${{ env.GIT_TAG }}) – you can copy directly from it, or edit for uniformity and clarity.
When you are done, merge this PR with the tag intact (**Do Not Squash** or rebase! Push new commits and **merge only**).
Feature branches should still be squashed, but \`release-pr\` must always be merged to complete the release.
pr_reviewer: ${{ github.actor }}
pr_draft: false
github_token: ${{ secrets.GITHUB_TOKEN }}