From 8ae6228ccf55dee099af2622bf4366fae704d9ea Mon Sep 17 00:00:00 2001 From: Tommy Barnes Date: Fri, 4 Feb 2022 11:29:58 -0500 Subject: [PATCH] Updated workflows, codeowner, .gitignore --- .github/workflows/release-pr.yml | 51 +-------- .github/workflows/tag-and-draft.yml | 10 ++ .github/workflows/tag-and-release.yml | 77 -------------- .gitignore | 3 + lib/run.js | 142 -------------------------- 5 files changed, 18 insertions(+), 265 deletions(-) create mode 100644 .github/workflows/tag-and-draft.yml delete mode 100644 .github/workflows/tag-and-release.yml delete mode 100644 lib/run.js diff --git a/.github/workflows/release-pr.yml b/.github/workflows/release-pr.yml index f2b0b3ef..ed7dd03b 100644 --- a/.github/workflows/release-pr.yml +++ b/.github/workflows/release-pr.yml @@ -1,4 +1,4 @@ -name: "Create release PR" +name: Create release PR on: workflow_dispatch: @@ -8,48 +8,7 @@ on: required: true jobs: - createPullRequest: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - name: Check if remote branch exists - env: - BRANCH: releases/${{ github.event.inputs.release }} - run: | - echo "##[set-output name=exists;]$(echo $(if [[ -z $(git ls-remote --heads origin ${BRANCH}) ]]; then echo false; else echo true; fi;))" - id: extract-branch-status - # these two only need to occur if the branch exists - - name: Checkout proper branch - if: ${{ steps.extract-branch-status.outputs.exists == 'true' }} - env: - BRANCH: releases/${{ github.event.inputs.release }} - run: git checkout ${BRANCH} - - name: Reset promotion branch - if: ${{ steps.extract-branch-status.outputs.exists == 'true' }} - run: | - git fetch origin main:main - git reset --hard main - - name: Install packages - run: | - rm -rf node_modules/ - npm install --no-bin-links - npm run build - - name: Remove node_modules from gitignore - run: | - sed -i '/node_modules/d' ./.gitignore - - name: Create branch - uses: peterjgrainger/action-create-branch@v2.0.1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - branch: releases/${{ github.event.inputs.release }} - - name: Create pull request - uses: peter-evans/create-pull-request@v3 - with: - token: ${{ secrets.GITHUB_TOKEN }} - commit-message: Add node modules and new code for release - title: ${{ github.event.inputs.release }} new release - base: releases/${{ github.event.inputs.release }} - branch: create-release + release-pr: + uses: OliverMKing/javascript-release-workflow/.github/workflows/release-pr.yml@main + with: + release: ${{ github.event.inputs.release }} \ No newline at end of file diff --git a/.github/workflows/tag-and-draft.yml b/.github/workflows/tag-and-draft.yml new file mode 100644 index 00000000..ef653d0e --- /dev/null +++ b/.github/workflows/tag-and-draft.yml @@ -0,0 +1,10 @@ +name: Tag and create release draft + +on: + push: + branches: + - releases/* + +jobs: + tag-and-release: + uses: OliverMKing/javascript-release-workflow/.github/workflows/tag-and-release.yml@main \ No newline at end of file diff --git a/.github/workflows/tag-and-release.yml b/.github/workflows/tag-and-release.yml deleted file mode 100644 index 89bc15a2..00000000 --- a/.github/workflows/tag-and-release.yml +++ /dev/null @@ -1,77 +0,0 @@ -name: "Tag and create release draft" - -on: - push: - branches: - - releases/* - -jobs: - gh_tagged_release: - runs-on: "ubuntu-latest" - - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - name: Test release - run: | - sudo npm install n - sudo n latest - npm test - - name: Get branch ending - run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF##*/} | sed 's:.*/::')" - id: extract-branch - - name: Get tags - run: | - echo "##[set-output name=tags;]$(echo $(git tag))" - id: extract-tags - - name: Get latest tag - uses: actions/github-script@v5 - env: - TAGS: ${{ steps.extract-tags.outputs.tags }} - BRANCH: ${{ steps.extract-branch.outputs.branch }} - with: - script: | - const tags = process.env["TAGS"] - .split(" ") - .map((x) => x.trim()); - const branch = process.env["BRANCH"]; - const splitTag = (x) => - x - .substring(branch.length + 1) - .split(".") - .map((x) => Number(x)); - function compareTags(nums1, nums2, position = 0) { - if (nums1.length < position && nums2.length < position) return nums2; - const num1 = splitTag(nums1)[position] || 0; - const num2 = splitTag(nums2)[position] || 0; - if (num1 === num2) return compareTags(nums1, nums2, position + 1); - else if (num1 > num2) return nums1; - else return nums2; - } - const branchTags = tags.filter((tag) => tag.startsWith(branch)); - if (branchTags.length < 1) return branch + ".-1" - return branchTags.reduce((prev, curr) => compareTags(prev, curr)); - result-encoding: string - id: get-latest-tag - - name: Get new tag - uses: actions/github-script@v5 - env: - PREV: ${{ steps.get-latest-tag.outputs.result }} - with: - script: | - let version = process.env["PREV"] - if (!version.includes(".")) version += ".0"; // case of v1 or v2 - const prefix = /^([a-zA-Z]+)/.exec(version)[0]; - const numbers = version.substring(prefix.length); - let split = numbers.split("."); - split[split.length - 1] = parseInt(split[split.length - 1]) + 1; - return prefix + split.join("."); - result-encoding: string - id: get-new-tag - - uses: "marvinpinto/action-automatic-releases@v1.2.1" - with: - title: ${{ steps.get-new-tag.outputs.result }} release - automatic_release_tag: ${{ steps.get-new-tag.outputs.result }} - repo_token: "${{ secrets.GITHUB_TOKEN }}" - draft: true diff --git a/.gitignore b/.gitignore index 016bf902..8ecdde7c 100644 --- a/.gitignore +++ b/.gitignore @@ -62,3 +62,6 @@ typings/ node_modules coverage + +# Transpiled JS +lib/ diff --git a/lib/run.js b/lib/run.js deleted file mode 100644 index 827ab1d8..00000000 --- a/lib/run.js +++ /dev/null @@ -1,142 +0,0 @@ -"use strict"; -// Copyright (c) Microsoft Corporation. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.walkSync = exports.findHelm = exports.downloadHelm = exports.getHelmDownloadURL = exports.getExecutableExtension = exports.getLatestHelmVersion = exports.run = void 0; -const os = require("os"); -const path = require("path"); -const util = require("util"); -const fs = require("fs"); -const toolCache = require("@actions/tool-cache"); -const core = require("@actions/core"); -const helmToolName = 'helm'; -const stableHelmVersion = 'v3.8.0'; -const helmAllReleasesUrl = 'https://api.github.com/repos/helm/helm/releases'; -function run() { - return __awaiter(this, void 0, void 0, function* () { - let version = core.getInput('version', { 'required': true }); - if (version.toLocaleLowerCase() === 'latest') { - version = yield getLatestHelmVersion(); - } - core.debug(util.format("Downloading %s", version)); - let cachedPath = yield downloadHelm(version); - try { - if (!process.env['PATH'].startsWith(path.dirname(cachedPath))) { - core.addPath(path.dirname(cachedPath)); - } - } - catch (_a) { - //do nothing, set as output variable - } - console.log(`Helm tool version: '${version}' has been cached at ${cachedPath}`); - core.setOutput('helm-path', cachedPath); - }); -} -exports.run = run; -// Downloads the helm releases JSON and parses all the recent versions of helm from it. -// Defaults to sending stable helm version if none are valid or if it fails -function getLatestHelmVersion() { - return __awaiter(this, void 0, void 0, function* () { - const helmJSONPath = yield toolCache.downloadTool(helmAllReleasesUrl); - try { - const helmJSON = JSON.parse(fs.readFileSync(helmJSONPath, 'utf-8')); - for (let i in helmJSON) { - if (isValidVersion(helmJSON[i].tag_name)) { - return helmJSON[i].tag_name; - } - } - } - catch (err) { - core.warning(util.format("Error while fetching the latest Helm release. Error: %s. Using default Helm version %s", err.toString(), stableHelmVersion)); - return stableHelmVersion; - } - return stableHelmVersion; - }); -} -exports.getLatestHelmVersion = getLatestHelmVersion; -// isValidVersion checks if verison is a stable release -function isValidVersion(version) { - return version.indexOf('rc') == -1; -} -function getExecutableExtension() { - if (os.type().match(/^Win/)) { - return '.exe'; - } - return ''; -} -exports.getExecutableExtension = getExecutableExtension; -function getHelmDownloadURL(version) { - switch (os.type()) { - case 'Linux': - return util.format('https://get.helm.sh/helm-%s-linux-amd64.zip', version); - case 'Darwin': - return util.format('https://get.helm.sh/helm-%s-darwin-amd64.zip', version); - case 'Windows_NT': - default: - return util.format('https://get.helm.sh/helm-%s-windows-amd64.zip', version); - } -} -exports.getHelmDownloadURL = getHelmDownloadURL; -function downloadHelm(version) { - return __awaiter(this, void 0, void 0, function* () { - let cachedToolpath = toolCache.find(helmToolName, version); - if (!cachedToolpath) { - let helmDownloadPath; - try { - helmDownloadPath = yield toolCache.downloadTool(getHelmDownloadURL(version)); - } - catch (exception) { - throw new Error(util.format("Failed to download Helm from location", getHelmDownloadURL(version))); - } - fs.chmodSync(helmDownloadPath, '777'); - const unzipedHelmPath = yield toolCache.extractZip(helmDownloadPath); - cachedToolpath = yield toolCache.cacheDir(unzipedHelmPath, helmToolName, version); - } - const helmpath = findHelm(cachedToolpath); - if (!helmpath) { - throw new Error(util.format("Helm executable not found in path", cachedToolpath)); - } - fs.chmodSync(helmpath, '777'); - return helmpath; - }); -} -exports.downloadHelm = downloadHelm; -function findHelm(rootFolder) { - fs.chmodSync(rootFolder, '777'); - var filelist = []; - exports.walkSync(rootFolder, filelist, helmToolName + getExecutableExtension()); - if (!filelist || filelist.length == 0) { - throw new Error(util.format("Helm executable not found in path", rootFolder)); - } - else { - return filelist[0]; - } -} -exports.findHelm = findHelm; -exports.walkSync = function (dir, filelist, fileToFind) { - var files = fs.readdirSync(dir); - filelist = filelist || []; - files.forEach(function (file) { - if (fs.statSync(path.join(dir, file)).isDirectory()) { - filelist = exports.walkSync(path.join(dir, file), filelist, fileToFind); - } - else { - core.debug(file); - if (file == fileToFind) { - filelist.push(path.join(dir, file)); - } - } - }); - return filelist; -}; -run().catch(core.setFailed);