Skip to content

Commit

Permalink
Maybe this will work
Browse files Browse the repository at this point in the history
  • Loading branch information
Tatskaari committed Sep 29, 2021
1 parent 9167dc4 commit 5ef4483
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea
node_modules
17 changes: 17 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: 'Release Action'
description: 'Creates github releases'
inputs:
release-files:
description: 'Files to attach to the release'
required: false
version-file:
description: 'File containing the current version'
required: true
default: "VERSION"
change-log:
description: 'File containing the change log'
required: true
default: "ChangeLog"
runs:
using: 'node12'
main: 'dist/index.js'
66 changes: 66 additions & 0 deletions src/release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const core = require('@actions/core');
const {GitHub, context} = require('@actions/github');
const fs = require('fs')

try {
const github = new GitHub(process.env.GITHUB_TOKEN);

// TODO(jpoole): validate this is a semver version
const version = fs.readFileSync("VERSION").toString().trim()
const changeLog = fs.readFileSync("ChangeLog").toString()

const changes = findTagChangelogs(changeLog, version)

github.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: "v"+version,
name: "v"+version,
body: changes,
prerelease: version.includes("beta") || version.includes("alpha") || version.includes("prerelease"),
target_commitish: context.sha,
}).catch(error => {
core.setFailed(error.message);
})
} catch (error) {
core.setFailed(error.message);
}

function findTagChangelogs(changelog, tag) {
const versionString = "Version " + tag

const lines = changelog.split("\n")
let foundVersion = false
let logs = []
for(let i = 0; i < lines.length; i++) {
let line = lines[i]
if (line.startsWith(versionString)) {
foundVersion = true
continue
}
if (!foundVersion) {
continue
}

if (line.startsWith("Version")) {
return logs.join("\n")
}

if (line.startsWith("-")) {
continue
}

line = line.trim()
if (line === "") {
continue
}
if (line.startsWith("*")) {
logs.push(line)
} else {
logs.push(" " + line)
}
}
return undefined
}

exports.findTagChangelogs = findTagChangelogs
56 changes: 56 additions & 0 deletions src/release.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const release = require("./release")

const testTest = `
Version 16.6.0
--------------
* Fixed issue with \`go_module()\` where adding the root package removed
all other items in the install list that came before #2019
* Fixed the linker flags in \`pip_library()\` for macOS #2015
* Added \`ExcludeGlob\` config option to the \`[Cover]\` section that
excludes files from coverage based on a glob pattern #2020 #2023
* Fix issue with \`go_module()\` where the incorrect release flags
were being applied when filtering third party go sourcews #2024
Version 16.5.1
--------------
* Fix nil pointer when tests fail in certain ways #2016
Version 16.5.0
--------------
* Singleflight all subincludes removing any potential for lockups #2002
* Implemented target level locking enabling multiple please instances to
build at the same time #2004
* Set a timeout on test result uploading #2008
* Updated to use go 1.17. This should be transparent to any users. #2010
* Various fixes and improvements around bash completions #1998 #2013
Version 16.4.2
--------------
* Honour require/provide for \`plz query revdeps\` and \`plz query changes\` #1997
* Fix \`plz tool langserver\` #1999
Version 16.4.1
--------------
* Fixed panic when downloading outputs for stamped targets that were retrived from
the cache #1994
`

const exepctedResult = `
* Singleflight all subincludes removing any potential for lockups #2002
* Implemented target level locking enabling multiple please instances to
build at the same time #2004
* Set a timeout on test result uploading #2008
* Updated to use go 1.17. This should be transparent to any users. #2010
* Various fixes and improvements around bash completions #1998 #2013
`

test("releaseParseTest", () => {
const result = release.findTagChangelogs(testTest, "16.5.0").trim()
expect(result).toContain(exepctedResult.trim())
})

0 comments on commit 5ef4483

Please sign in to comment.