-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from PTFS-Europe/v1.5
V1.5
- Loading branch information
Showing
7 changed files
with
247 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Upload Release Asset | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
tags: | ||
- 'v*' | ||
|
||
jobs: | ||
release: | ||
name: Create Release and upload .kpz file | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
- name: Version | ||
run: | | ||
VERSION=$(node checkVersionNumber.js version) | ||
FILENAME=$(node checkVersionNumber.js filename) | ||
echo "VERSION=$VERSION" >> $GITHUB_ENV | ||
echo "FILENAME=$FILENAME" >> $GITHUB_ENV | ||
- name: 'Create Release' | ||
run: gh release create ${{ env.VERSION }} ${{ env.FILENAME }} -t ${{ env.VERSION }} -n "" | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
const checkType = process.argv[2] | ||
|
||
const getFormattedRemotes = (input) => { | ||
const numberOfRemotes = input.length | ||
const remotes = [] | ||
|
||
for(let i = 0; i < numberOfRemotes; i = i + 3) { | ||
const [remote, url, type] = input.slice(i, i + 3) | ||
remotes.push({ | ||
remote, | ||
url, | ||
type | ||
}) | ||
} | ||
|
||
const validRemotes = remotes.filter(remote => remote.type === '(push)').reduce((result, remote) => { | ||
if(remote.url !== '[email protected]:PTFS-Europe/koha-plugin-template.git' && | ||
remote.url !== 'https://github.com/PTFS-Europe/koha-plugin-template.git') { | ||
result.push(remote) | ||
} | ||
return result | ||
}, []) | ||
|
||
return validRemotes | ||
} | ||
|
||
if(checkType === 'check') { | ||
const cliInput = process.argv.slice(3) | ||
|
||
const validRemotes = getFormattedRemotes(cliInput) | ||
|
||
if(validRemotes.length === 0) console.log('No valid remotes') | ||
if(validRemotes.length === 1) return console.log(validRemotes[0].remote) | ||
|
||
if(validRemotes.length > 1) console.log('Multiple remotes available') | ||
} | ||
if(checkType === 'validate') { | ||
const response = process.argv.slice(3, 4)[0].split('-')[0] | ||
const remoteList = process.argv.slice(4) | ||
|
||
const validRemotes = getFormattedRemotes(remoteList).map(i => i.remote) | ||
|
||
const checkRemoteIsValid = validRemotes.indexOf(response) | ||
|
||
if(checkRemoteIsValid > -1) return console.log(response) | ||
if(checkRemoteIsValid === -1) return console.log('Invalid') | ||
} | ||
if(checkType === 'provide') { | ||
const cliInput = process.argv.slice(3) | ||
|
||
const validRemotes = getFormattedRemotes(cliInput) | ||
|
||
const remoteStrings = validRemotes.map(remote => { | ||
return `${remote.remote}-${remote.url}` | ||
}) | ||
|
||
console.log(...remoteStrings) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
const identifyPluginFile = (file) => { | ||
const pluginFile = fs.readFileSync(file, 'utf8') | ||
const fileByLine = pluginFile.split(/\r?\n/) | ||
|
||
let pluginIdentified = false | ||
fileByLine.forEach(line => { | ||
if(line.includes("Koha::Plugins::Base")){ | ||
pluginIdentified = true | ||
} | ||
}) | ||
return pluginIdentified | ||
} | ||
|
||
const collectPluginFiles = (fullPath) => { | ||
let files = [] | ||
fs.readdirSync(fullPath).forEach(file => { | ||
const absolutePath = path.join(fullPath, file) | ||
if (fs.statSync(absolutePath).isDirectory()) { | ||
const filesFromNestedFolder = collectPluginFiles(absolutePath) | ||
filesFromNestedFolder && filesFromNestedFolder.forEach(file => { | ||
files.push(file) | ||
}) | ||
} else { | ||
return files.push(absolutePath) | ||
} | ||
}) | ||
return files | ||
} | ||
|
||
const pluginFiles = collectPluginFiles('./Koha') | ||
|
||
let pluginFilePath | ||
pluginFiles.forEach(file => { | ||
const pluginFile = identifyPluginFile(file) | ||
if(pluginFile) { | ||
pluginFilePath = file | ||
} | ||
}) | ||
if(!pluginFilePath) return console.log('No plugin file found') | ||
|
||
const cliInput = process.argv.slice(2)[0] | ||
|
||
if(cliInput === 'filename') { | ||
const filename = pluginFilePath.replace(/^.*[\\\/]/, '').toLowerCase() | ||
const removeFileExtension = path.parse(filename).name | ||
const kpzFileName = `koha-plugin-${removeFileExtension}.kpz` | ||
console.log(kpzFileName) | ||
} | ||
if(cliInput === 'version') { | ||
const pluginFile = fs.readFileSync(pluginFilePath, 'utf8') | ||
const fileByLine = pluginFile.split(/\r?\n/) | ||
|
||
let versionNumberIdentified | ||
fileByLine.forEach((line, index)=> { | ||
if(line.includes("our $VERSION")){ | ||
versionNumberIdentified = index | ||
} | ||
}) | ||
|
||
if(!versionNumberIdentified) return console.log('No version found') | ||
if(versionNumberIdentified) { | ||
const regex = /our \$VERSION\s*=\s*(["'`]?)([\d.]+)\1;/ | ||
const findVersionNumber = regex.exec(fileByLine[versionNumberIdentified]) | ||
const pluginVersion = findVersionNumber[2] | ||
console.log(`v${pluginVersion}`) | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "koha-plugin-template", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"release": "bash ./release_kpz.sh" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/usr/bin/env bash | ||
|
||
RED="\033[0;31m" | ||
NC="\033[0m" # No colour | ||
GREEN="\033[0;32m" | ||
YELLOW="\033[1;33m" | ||
|
||
echo "Creating and releasing .kpz file" | ||
|
||
FILENAME=$(node checkVersionNumber.js filename) | ||
FILE=./${FILENAME} | ||
|
||
if test -f "$FILE"; then | ||
echo "Plugin .kpz file already exists, previous version deleted" | ||
rm -r "$FILE" | ||
fi | ||
echo "Creating new .kpz file" | ||
zip -r "$FILE" Koha/ | ||
|
||
NEW_VERSION=$(node checkVersionNumber.js version) | ||
|
||
if [ "$NEW_VERSION" = "No plugin file found" ]; then | ||
echo -e "${RED}No plugin file could be identified, have you created one?" | ||
echo -e "A plugin file must contain "use base qw\(Koha::Plugins::Base\);"${NC}" | ||
exit | ||
elif [ "$NEW_VERSION" = "No version found" ]; then | ||
echo -e "${RED}No version could be identified, does your plugin file include one?" | ||
echo -e "A plugin file must contain "our \$VERSION = "version here";"${NC}" | ||
exit | ||
else | ||
NEW_VERSION_NUMBER=${NEW_VERSION:1} | ||
fi | ||
|
||
PREVIOUS_VERSION=$(git log --pretty=oneline | grep -m 1 -o "v[0-9.]\{1,6\}") | ||
if [ -z "$PREVIOUS_VERSION" ]; then | ||
echo -e "${YELLOW}No previous version found. Assuming this is the first release.${NC}" | ||
PREVIOUS_VERSION_NUMBER="v0.0.0" # Assuming 0 as the initial version for comparison | ||
else | ||
PREVIOUS_VERSION_NUMBER=${PREVIOUS_VERSION:1} | ||
fi | ||
echo -e "Previous version: $PREVIOUS_VERSION" | ||
echo -e "New version: $NEW_VERSION" | ||
|
||
# Comparing versions | ||
VERSION_COMPARISON=$(echo -e "$PREVIOUS_VERSION_NUMBER\n$NEW_VERSION_NUMBER" | sort -V | head -n 1) | ||
echo -e "Version comparison: $VERSION_COMPARISON" | ||
|
||
if [ "$VERSION_COMPARISON" != "$PREVIOUS_VERSION_NUMBER" ]; then | ||
echo -e "${GREEN}Version has been updated from $PREVIOUS_VERSION_NUMBER to $NEW_VERSION_NUMBER - checking remotes and starting upload${NC}" | ||
|
||
REMOTES=$(git remote -v) | ||
VALID_REMOTE=$(node checkRemotes.js check $REMOTES) | ||
|
||
if [ "$VALID_REMOTE" = "No valid remotes" ]; then | ||
echo -e "${RED}You have not set a git remote, please set one to push${NC}" | ||
exit | ||
elif [ "$VALID_REMOTE" = "Multiple remotes available" ]; then | ||
REMOTE_LIST=$(node checkRemotes.js provide $REMOTES) | ||
echo -e "${RED}Multiple git remotes identified, which one would you like to select?${NC}\n" | ||
PS3="Select a number:" | ||
select REMOTE in $REMOTE_LIST | ||
do | ||
echo "Selected remote: $REMOTE\n" | ||
break | ||
done | ||
VALID_REMOTE=$(node checkRemotes.js validate $REMOTE $REMOTES) | ||
fi | ||
|
||
git add . | ||
git commit -m "$NEW_VERSION" | ||
git tag "$NEW_VERSION" | ||
git push $VALID_REMOTE | ||
echo -e "${GREEN}Plugin has been pushed to Github and a release is being generated${NC}" | ||
else | ||
echo -e "${RED}WARNING: The Plugin version needs to be updated - please check the .pm file and update the version${NC}" | ||
fi |