Skip to content

Commit

Permalink
Revert last commit - does not work with branch protection (#317)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenfuqua authored Nov 13, 2023
1 parent b752c4d commit be106a6
Show file tree
Hide file tree
Showing 9 changed files with 6,205 additions and 37 deletions.
47 changes: 11 additions & 36 deletions .github/workflows/on-merge-to-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,56 +14,31 @@ env:
GITHUB_TOKEN: ${{ secrets.PAT_ATTACH_TO_RELEASE }}

jobs:
upgrade:
name: Upgrade packages
runs-on: ubuntu-latest
defaults:
run:
working-directory: Meadowlark-js
permissions:
contents: write
outputs:
version: ${{ steps.set-version.outputs.version }}
steps:
- name: Checkout the Repo
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0

- name: Update versions
run: npx [email protected] version prerelease --exact --no-git-tag-version --yes

- name: Set Version
id: set-version
run: |
version=v$(cat lerna.json | jq -r .version)
echo "version=$version" >> "$GITHUB_OUTPUT"
- uses: planetscale/ghcommit-action@4131649dbf2fdf1eb34421702972a5af7b0a8731 # v0.1.18
with:
commit_message: "${{ steps.set-version.outputs.version }}"
repo: ${{ github.repository }}
branch: ${{ github.head_ref || github.ref_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

create-pre-releases:
name: Create Pre-Releases
runs-on: ubuntu-latest
needs: upgrade
defaults:
run:
shell: pwsh
working-directory: Meadowlark-js
working-directory: eng/version
steps:
- name: Checkout the Repo
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
with:
# Need full Git history for calculating the version number
fetch-depth: 0w

- name: Create Meadowlark Pre-Release
run: |
npm install
$version = $(node ./bump.js)
if ($LASTEXITCODE -ne 0) {
throw 'Unable to retrieve version number'
}
$version="${{needs.upgrade.outputs.version}}"
"Creating pre-release $version" | Out-Host
$body = @{
tag_name = $version
tag_name = "$version"
target_commitish = "main"
name = $version
body = ""
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/on-prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
with:
# Need full Git history for calculating the version number
fetch-depth: 0

- name: Setup Node
uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3.5.1
Expand All @@ -39,8 +42,15 @@ jobs:
cache-dependency-path: "**/package-lock.json"

- name: Install dependencies
if: ${{ steps.modules-cache.outputs.cache-hit != 'true' }}
run: npm ci

- name: Update version to match tag
working-directory: eng/version
run: |
npm ci --omit dev
node ./set.js ${{ env.REF }}
- name: Transpile to JS
run: npm run build --workspaces

Expand All @@ -64,6 +74,9 @@ jobs:
- name: Publish
run: npm publish --workspaces --tag dev
# NOTE: there are uncommitted version number changes in package.json. No
# problem! Our strategy is to rely on the tag history for version numbers,
# not on package.json.

- name: Generate hash codes for npm tarballs
id: hash-code
Expand Down
2 changes: 1 addition & 1 deletion Meadowlark-js/lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"packages": [
"packages/*"
],
"version": "v0.3.7-pre.0",
"version": "v0.3.0-pre-35",
"npmClient": "npm",
"useWorkspaces": true,
"command": {
Expand Down
27 changes: 27 additions & 0 deletions eng/version/bump.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: Apache-2.0
// Licensed to the Ed-Fi Alliance under one or more agreements.
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0.
// See the LICENSE and NOTICES files in the project root for more information.

/*
* Calculates the next version number based on prior tag and commit depth. NO
* COMMIT.
*/

const { calculateNextVersion, callShellCommand } = require('./helper');

// `git describe` returns the last tag plus the commit depth and the short hash
// for the most recent commit. Example: last tag was v0.3.0, there has been one
// more commit, and the most recent has hash `g1636c72`; then the output will be
// `v0.3.1-1-g1636c72`
const gitDescribe = callShellCommand('git describe --first-parent --tags');

const version = calculateNextVersion(gitDescribe);
if (version === null) {
// eslint-disable-next-line no-console
console.error(`Unable to extract version information from ${gitDescribe}`);
process.exit(1);
}

// eslint-disable-next-line no-console
console.info(version);
51 changes: 51 additions & 0 deletions eng/version/helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// SPDX-License-Identifier: Apache-2.0
// Licensed to the Ed-Fi Alliance under one or more agreements.
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0.
// See the LICENSE and NOTICES files in the project root for more information.

const { execSync } = require('child_process');

/* Cases that this code must handle:
* 1. Last tag was a release version and there have been no commits: then keep
* that tag. v0.3.0 --> v0.3.0
* 2. Last tag was a release version and there have been some commits: then
* calculate depth and create a pre-release. v0.3.0-10-gbad82c2 ->
* v0.3.0-pre-10.
* 3. Last tag was a pre-release version and there have been no commits: keep
* the tag. v0.3.0-pre-10 --> v0.3.0-pre-10.
* 4. Last tag was a pre-release version and there have been no commits: get the
* new depth and add it to the prior depth. v0.3.0-pre-10-3-hcbd82c2 -->
* v0.3.0-pre-13.
*/
function calculateNextVersion(gitDescribe) {
let version = gitDescribe;
const properTagExpr = /^v[^-]+(?:-pre-\d+)$/;
if (!gitDescribe.match(properTagExpr)) {
// Parse out the components
const versionExpr = /^(?<base>v[^-]+)((-pre-(?<pre>\d+))?-(?<depth>\d+)-.{8})?/;
const versionMatch = gitDescribe.match(versionExpr);
if (!versionMatch) {
return null;
}

let { base, pre, depth } = versionMatch.groups;

version = base;
pre = pre ?? "0";
depth = depth ?? "0";
if (pre != "0" || depth != "0") {
version = `${version}-pre-${Number.parseInt(pre, 10) + Number.parseInt(depth, 10)}`;
}
}

return version;
}

function callShellCommand(cmd, options) {
return execSync(cmd, options).toString().replace('\n', '');
}

module.exports = {
calculateNextVersion,
callShellCommand
};
18 changes: 18 additions & 0 deletions eng/version/helper.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: Apache-2.0
// Licensed to the Ed-Fi Alliance under one or more agreements.
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0.
// See the LICENSE and NOTICES files in the project root for more information.

const { calculateNextVersion } = require('./helper');

describe('given input from `git describe`', () => {
describe('when calculating the next version', () => {
it.each([
['v0.3.0','v0.3.0'],
['v0.3.0-10-gbad82c2','v0.3.0-pre-10'],
['v0.3.0-pre-10','v0.3.0-pre-10'],
['v0.3.0-pre-10-3-hcbd82c2','v0.3.0-pre-13']
])('builds a proper semantic version from %s', (gitDescribe, expected) => {
expect(calculateNextVersion(gitDescribe)).toBe(expected);
});});
});
Loading

0 comments on commit be106a6

Please sign in to comment.