Skip to content

Commit

Permalink
Enable releases to Marketplaces
Browse files Browse the repository at this point in the history
Signed-off-by: Fred Bricon <[email protected]>
  • Loading branch information
fbricon committed Oct 15, 2024
1 parent 462d5cb commit 13420ae
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 1 deletion.
124 changes: 124 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
name: Release build

on:
schedule:
- cron: "0 8 * * *"
workflow_dispatch:
inputs:
EXTENSION_TAG:
description: "branch/tag of the extension to build."
type: string
default: main
publishPreRelease:
description: "Publish a pre-release ?"
required: true
type: choice
options:
- "true"
- "false"
default: "true"
publishToMarketPlace:
description: "Publish to VS Code Marketplace ?"
required: true
type: choice
options:
- "true"
- "false"
default: "false"
publishToOVSX:
description: "Publish to OpenVSX Registry ?"
required: true
type: choice
options:
- "true"
- "false"
default: "false"
jobs:
should-build-change:
runs-on: ubuntu-latest
outputs:
repo-cache-hit: ${{ steps.cache-last-commit.outputs.cache-hit }}
steps:
- uses: actions/checkout@v4
- run: |
git rev-parse HEAD >> ./lastCommit
- name: Check New Changes
id: cache-last-commit
uses: actions/cache@v4
with:
path: lastCommit
key: lastCommit-${{ hashFiles('lastCommit') }}

release-job:
runs-on: ubuntu-latest
needs: should-build-change
if: ${{ needs.should-build-change.outputs.repo-cache-hit != 'true' || github.event_name != 'schedule' }}
steps:
- name: Checkout Extension
uses: actions/checkout@v4
with:
ref: ${{ inputs.EXTENSION_TAG }}

- name: Set Up NodeJS
uses: actions/setup-node@v4
with:
node-version: '20'

# Run install dependencies
- name: Install dependencies
run: npm run install:ci

- name: Extract version
run: |
echo "EXT_VERSION=$(cat package.json | jq -r .version)" >> $GITHUB_ENV
- name: Prepare Pre-Release version
if: ${{ github.event_name == 'schedule' || inputs.publishPreRelease == 'true' }}
run: |
node ./releng/create-package-insiders-json.js
mv ./package.insiders.json ./package.json
echo "publishPreReleaseFlag=--pre-release" >> $GITHUB_ENV
- name: Package extension
run: |
npx @vscode/vsce package ${{ env.publishPreReleaseFlag }}
- name: Publish to GH Release Tab
if: ${{ github.event_name != 'schedule' && inputs.publishPreRelease == 'false' }}
uses: "marvinpinto/action-automatic-releases@919008cf3f741b179569b7a6fb4d8860689ab7f0"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: "${{ env.EXT_VERSION }}"
title: "${{ env.EXT_VERSION }}"
draft: true
files: |
vscode-granite-*.vsix
- name: Publish to VS Code Marketplace
if: ${{ github.event_name == 'schedule' || inputs.publishToMarketPlace == 'true' || inputs.publishPreRelease == 'true' }}
run: |
npx @vscode/vsce publish -p ${{ secrets.VSCODE_MARKETPLACE_TOKEN }} --packagePath vscode-granite-*.vsix
- name: Publish to OpenVSX Registry
if: ${{ github.event_name == 'schedule' || inputs.publishToOVSX == 'true' || inputs.publishPreRelease == 'true' }}
run: |
npx ovsx publish -p ${{ secrets.OVSX_MARKETPLACE_TOKEN }} --packagePath vscode-granite-*.vsix
post-release-job:
if: ${{ inputs.publishToMarketPlace == 'true' && inputs.publishToOVSX == 'true' && inputs.EXTENSION_TAG == 'main' }}
runs-on: ubuntu-latest
needs: release-job
steps:
- name: Check out Extension
uses: actions/checkout@v4
- name: Set Up NodeJS
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Upversion for Development
run: |
tag=`npm version --no-git-tag-version patch`
git config --global user.email "[email protected]"
git config --global user.name "redhat-developer-bot"
git commit -am "Upversion to ${tag#v}"
git push origin
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vscode-granite",
"displayName": "Granite Code AI-Assistant",
"displayName": "Granite Code Assistant",
"description": "Use IBM Granite Code LLM as your Code Assistant",
"publisher": "redhat",
"version": "0.0.1",
Expand Down
33 changes: 33 additions & 0 deletions releng/create-package-insiders-json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//Copied from https://github.com/microsoft/vscode-maven/blob/main/scripts/create-package-insiders-json.js
const fs = require("fs");

const json = JSON.parse(fs.readFileSync("./package.json").toString());
const stableVersion = json.version.match(/(\d+)\.(\d+)\.(\d+)/);
const major = stableVersion[1];
const minor = stableVersion[2];

function prependZero(number) {
if (number > 99) {
throw new Exception("Unexpected value to prepend with zero");
}
return `${number < 10 ? "0" : ""}${number}`;
}

const date = new Date();
const month = date.getMonth() + 1;
const day = date.getDate();
const hours = date.getHours();
const minutes = date.getMinutes();

//Can't use minutes and seconds to prevent failures from 2 build running in the same minute
//because each number must be in the range to 2147483647
//1% of the minutes in a day = 14.4 minutes. So we can publish about every 15 min.
const minutesElapsed = hours * 60 + minutes;
const percentage = Math.floor((minutesElapsed / 1440) * 100);
patch = `${date.getFullYear()}${prependZero(month)}${prependZero(day)}${prependZero(percentage)}`;

const insiderPackageJson = Object.assign(json, {
version: `${major}.${minor}.${patch}`,
});

fs.writeFileSync("./package.insiders.json", JSON.stringify(insiderPackageJson));

0 comments on commit 13420ae

Please sign in to comment.