Skip to content
Permalink
Browse files

auto-generate changelog for release page on travis, cleanup build.sh

  • Loading branch information...
hobbyquaker committed Apr 29, 2018
1 parent 80913c9 commit 2c66f50b2a3c4b422c6f5c13d06d30ede8cf037f
Showing with 95 additions and 14 deletions.
  1. +1 −0 .gitignore
  2. +5 −3 .travis.yml
  3. +40 −11 build.sh
  4. +49 −0 github_release.rb
@@ -3,3 +3,4 @@ dist
.idea
.DS_Store
live
CHANGELOG.md
@@ -9,15 +9,17 @@ branches:
only:
- master
before_deploy:
- ./build.sh
- source ./addon_tmp/node-red/versions
- git config --local user.name "hobbyquaker"
- git config --local user.email "hobbyquaker@gmail.com"
- ./build.sh
- source ./addon_tmp/node-red/versions
- git tag "v$ADDON_VERSION-$TRAVIS_BUILD_NUMBER"
deploy:
provider: releases
api_key: $GITHUB_OAUTH_TOKEN
file_glob: true
file: dist/*
skip_cleanup: true
body: Node.js $NODE_VERSION - npm $NPM_VERSION - Node-RED $RED_VERSION - Node-RED Dashboard $DASHBOARD_VERSION - node-red-contrib-ccu $RED_CCU_VERSION
after_deploy:
- gem install octokit
- ./github_release.rb -s $GITHUB_OAUTH_TOKEN -r hobbyquaker/ccu-addon-node-red -c CHANGELOG.md -t v$ADDON_VERSION-$TRAVIS_BUILD_NUMBER
@@ -13,21 +13,25 @@ ADDON_TMP=$BUILD_DIR/addon_tmp

mkdir $ADDON_TMP 2> /dev/null || rm -r $ADDON_TMP/*


echo "download and extract Node.js $NODE_URL ..."
curl --silent $NODE_URL | tar -xJf - -C $ADDON_TMP
mv $ADDON_TMP/$NODE_NAME $ADDON_TMP/node-red
rm $ADDON_TMP/node-red/README.md
rm $ADDON_TMP/node-red/CHANGELOG.md
mv $ADDON_TMP/node-red/LICENSE $ADDON_TMP/node-red/LICENSE_Nodejs


echo "copying files to tmp dir..."
cp -r $ADDON_FILES/* $ADDON_TMP/


echo "installing node modules..."
cp package.json $ADDON_TMP/node-red/
cd $ADDON_TMP/node-red
echo "installing node modules..."
npm install --silent --no-package-lock --production --no-optional --global-style


echo "adapt Node-RED..."
rm -r $ADDON_TMP/node-red/node_modules/node-red/nodes/core/hardware
#mv $ADDON_TMP/node-red/node_modules/node-red/red/runtime/nodes/registry/installer.js $ADDON_TMP/node-red/node_modules/node-red/red/runtime/nodes/registry/installer.js.orig
@@ -36,29 +40,54 @@ mv $ADDON_TMP/node-red/node_modules/node-red/red/runtime/log.js $ADDON_TMP/node-
sed "s/util\.log/console.log/g" $ADDON_TMP/node-red/node_modules/node-red/red/runtime/log.js.orig > $ADDON_TMP/node-red/node_modules/node-red/red/runtime/log.js



echo "moving node modules to lib dir..."
cp -r $ADDON_TMP/node-red/node_modules $ADDON_TMP/node-red/lib/
rm -r $ADDON_TMP/node-red/node_modules

cd $BUILD_DIR


echo "creating version file"
ADDON_VERSION=`jq -r '.version' $ADDON_TMP/node-red/package.json`
echo "export ADDON_VERSION=$ADDON_VERSION" > $ADDON_TMP/node-red/versions
echo "export NODE_VERSION=$NODE_VERSION" >> $ADDON_TMP/node-red/versions
echo "export NPM_VERSION=`jq -r '.version' $ADDON_TMP/node-red/lib/node_modules/npm/package.json`" >> $ADDON_TMP/node-red/versions
echo "export RED_VERSION=`jq -r '.version' $ADDON_TMP/node-red/lib/node_modules/node-red/package.json`" >> $ADDON_TMP/node-red/versions
echo "export DASHBOARD_VERSION=`jq -r '.version' $ADDON_TMP/node-red/lib/node_modules/node-red-dashboard/package.json`" >> $ADDON_TMP/node-red/versions
echo "export RED_CCU_VERSION=`jq -r '.version' $ADDON_TMP/node-red/lib/node_modules/node-red-contrib-ccu/package.json`" >> $ADDON_TMP/node-red/versions
NPM_VERSION=`jq -r '.version' $ADDON_TMP/node-red/lib/node_modules/npm/package.json`
RED_VERSION=`jq -r '.version' $ADDON_TMP/node-red/lib/node_modules/node-red/package.json`
DASHBOARD_VERSION=`jq -r '.version' $ADDON_TMP/node-red/lib/node_modules/node-red-dashboard/package.json`
RED_CCU_VERSION=`jq -r '.version' $ADDON_TMP/node-red/lib/node_modules/node-red-contrib-ccu/package.json`

cat >$ADDON_TMP/node-red/versions <<EOL
export ADDON_VERSION=$ADDON_VERSION
export NODE_VERSION=$NODE_VERSION
export NPM_VERSION=$NPM_VERSION
export RED_VERSION=$RED_VERSION
export DASHBOARD_VERSION=$DASHBOARD_VERSION
export RED_CCU_VERSION=$RED_CCU_VERSION
EOL


echo "creating changelog file"
cat >CHANGELOG.md <<EOL
### Module Versions
* Node.js $NODE_VERSION
* npm $NPM_VERSION
* Node-RED $RED_VERSION
* Node-RED Dashboard $DASHBOARD_VERSION
* node-red-contrib-ccu $RED_CCU_VERSION
### Changelog
EOL

git log `git describe --tags --abbrev=0`..HEAD --pretty=format:'* %h @%an %s' >> CHANGELOG.md

cat $ADDON_TMP/node-red/versions

ADDON_FILE=ccu-addon-node-red-$ADDON_VERSION.tar.gz
echo "compressing addon package $ADDON_FILE ..."
ADDON_FILE=ccu-addon-node-red-$ADDON_VERSION.tar.gz
mkdir $BUILD_DIR/dist 2> /dev/null
cd $ADDON_TMP
tar --exclude=.DS_Store -czf $BUILD_DIR/dist/$ADDON_FILE *
cd $BUILD_DIR

echo "done."

echo "done."
@@ -0,0 +1,49 @@
#!/usr/bin/env ruby

# Copied from https://gist.github.com/valeriomazzeo/5491aee76f758f7352e2e6611ce87ec1

require 'optparse'
require 'octokit'

options = {}
OptionParser.new do |opt|
opt.on('-s', '--secret SECRET', 'GitHub access token') { |o| options[:secret] = o }
opt.on('-r', '--repo-slug REPO_SLUG', 'Repo slug. i.e.: apple/swift') { |o| options[:repo_slug] = o }
opt.on('-c', '--changelog-file CHANGELOG_FILE', 'Changelog path') { |o| options[:changelog_file] = o }
opt.on('-t', '--tag TAG', 'Tag name') { |o| options[:tag_name] = o }
end.parse!

raise OptionParser::MissingArgument if options[:secret].nil?
raise OptionParser::MissingArgument if options[:repo_slug].nil?
raise OptionParser::MissingArgument if options[:changelog_file].nil?
raise OptionParser::MissingArgument if options[:tag_name].nil?

client = Octokit::Client.new(:access_token => options[:secret])
user = client.user
user.login

unless client.scopes.include? 'public_repo' or client.scopes.include? 'repo'
raise Error, "Insufficient permissions. Make sure your token contains the repo or public_repo scope."
end

puts "Logged in as #{user.name}"
puts "Deploying to repo: #{options[:repo_slug]}"

tag_matched = false
release_url = nil
releases = client.releases(options[:repo_slug])
body = File.open(options[:changelog_file], "rb").read

releases.each do |release|
if release.tag_name == options[:tag_name]
release_url = release.rels[:self].href
tag_matched = true
end
end

# if tag has been pushed directly to git, create a github release
if tag_matched == false
client.create_release(options[:repo_slug], options[:tag_name], { :name => options[:tag_name], :body => body })
else
client.update_release(release_url, { :name => options[:tag_name], :body => body })
end

0 comments on commit 2c66f50

Please sign in to comment.
You can’t perform that action at this time.