Skip to content

Commit

Permalink
Merge pull request #230 from czechboy0/hd/sparkle_develop
Browse files Browse the repository at this point in the history
Adding Sparkle autoupdater
  • Loading branch information
czechboy0 committed Feb 3, 2016
2 parents a8dac52 + 37c1b5c commit 72f8b38
Show file tree
Hide file tree
Showing 8 changed files with 326 additions and 16 deletions.
2 changes: 1 addition & 1 deletion BuildaKit/PersistenceMigrator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation
import BuildaUtils
import XcodeServerSDK
@testable import BuildaGitServer
import BuildaGitServer

public protocol MigratorType {
init(persistence: Persistence)
Expand Down
1 change: 1 addition & 0 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def buildasaur_app_pods
rac
pod 'Ji', '~> 1.2.0'
pod 'CryptoSwift'
pod 'Sparkle'
end

def test_pods
Expand Down
3 changes: 3 additions & 0 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ PODS:
- ReactiveCocoa/Core
- Result (~> 1.0)
- Result (1.0.1)
- Sparkle (1.13.1)
- SwiftSafe (0.1)
- XcodeServerSDK (0.5.6):
- BuildaUtils (~> 0.2.3)
Expand All @@ -46,6 +47,7 @@ DEPENDENCIES:
- Nimble (~> 3.0.0)
- OAuthSwift
- ReactiveCocoa (= 4.0.0-RC.1)
- Sparkle
- XcodeServerSDK (~> 0.5.6)

EXTERNAL SOURCES:
Expand All @@ -67,6 +69,7 @@ SPEC CHECKSUMS:
OAuthSwift: f2e0de083739da5697be095c9af2671242a4ed8b
ReactiveCocoa: 2b0f654beb7642b82cfd3fdb845205ae9889422c
Result: caef80340451e1f07492fa1e89117f83613bce24
Sparkle: 2fbd47b869621d1e679c7554e3e19dda02104818
SwiftSafe: 77ffd12b02678790bec1ef56a2d14ec5036f1fd6
XcodeServerSDK: 6300badc4a799da9ad6e970b366eda18d4a47bda

Expand Down
93 changes: 81 additions & 12 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ update_fastlane

# This is the minimum version number required.
# Update this, if you use features of a newer version
fastlane_version "1.26.0"
fastlane_version "1.57.0"

before_all do |lane|
end
Expand Down Expand Up @@ -76,27 +76,90 @@ end
lane :release do
run_tests
build
release_no_build
release_app
end

lane :release_app do
raise "No built app found in ./build/Buildasaur.app" unless File.exist?("../build/Buildasaur.app")
version = get_info_plist_value(
key: "CFBundleShortVersionString",
path: "Buildasaur/Info.plist"
)
github(
assets: ["./build/Buildasaur.app"],
version: version

app_path = "../build/Buildasaur.app"
raise "No built app found in #{app_path}" unless File.exist?(app_path)

app_zip_path = zip_app_bundle(app_path: app_path)
raise "No zipped app found in #{app_zip_path}" unless File.exist?(app_zip_path)

ENV['FL_GET_INFO_PLIST_PATH'] = File.absolute_path("#{app_path}/Contents/Info.plist")
human_version = get_info_plist_value(key: "CFBundleShortVersionString")
machine_version = get_info_plist_value(key: "CFBundleVersion")

release_info = github(
assets: [app_zip_path],
version: human_version
)
# release_info = {
# title: "v1.0-beta1 - Hello!",
# description: "# Hey\n[Link](http://here)",
# version_tag: "v1.0-beta1"
# }
sparkle(
app_zip_path: app_zip_path,
release_title: release_info[:title],
release_description: release_info[:description],
release_version_tag: release_info[:version_tag],
machine_version: machine_version,
human_version: human_version
)

UI.message "Now review and commit changes to the repository!"
end

private_lane :zip_app_bundle do |params|
app_path = params[:app_path]
app_zip_path = "#{app_path}.zip"
abs_app_path = File.absolute_path(app_path)
app_folder = File.dirname(abs_app_path)
sh "cd '#{app_folder}'; zip -r --symlinks '#{File.basename(app_zip_path)}' '#{File.basename(app_path)}'"
File.absolute_path(app_zip_path)
end

lane :build do
gym(
scheme: 'Buildasaur',
output_name: 'Buildasaur',
output_directory: './build'
output_directory: './build',
export_method: 'developer-id'
)
end

private_lane :sparkle do |params|

# Create release notes file
release_notes_html = render_github_markdown(
context_repository: "czechboy0/Buildasaur",
api_token: ENV["GITHUB_TOKEN"],
markdown_contents: params[:release_description]
)
release_notes_html_path = File.absolute_path("../Meta/Sparkle_Release_Notes/#{params[:release_version_tag]}.html")
File.open(release_notes_html_path, "w") { |io| io.write(release_notes_html) }
# Now we need to commit this new file at the end of the workflow!
sh "cd .. && git add '#{release_notes_html_path}'"

release_notes_html_url = "https://raw.githubusercontent.com/czechboy0/Buildasaur/master/Meta/Sparkle_Release_Notes/#{params[:release_version_tag]}.html"
app_download_url = "https://github.com/czechboy0/Buildasaur/releases/download/#{params[:release_version_tag]}/Buildasaur.app.zip"

UI.message "Successfully created release notes file at path #{release_notes_html_path}"

sparkle_add_update(
feed_file: "sparkle.xml",
app_download_url: app_download_url,
app_size: "#{File.size(params[:app_zip_path])}",
machine_version: params[:machine_version],
human_version: params[:human_version],
title: params[:release_title],
release_notes_link: release_notes_html_url,
deployment_target: "10.11"
)

UI.message "Successfully added a release item to the Sparkle XML file (review before committing)"
end

private_lane :github do |params|
Expand All @@ -117,14 +180,15 @@ private_lane :github do |params|
title = prompt(text: 'Release Title: ')
description = prompt(text: "Release changelog: ",
multi_line_end_keyword: "END")
release_name = [version_tag, title].join(" - ")

# create a new release on GitHub
repo_url = "czechboy0/Buildasaur"
ENV["FL_GITHUB_RELEASE_API_TOKEN"] = ENV["GITHUB_TOKEN"]
release = set_github_release(
repository_name: repo_url,
upload_assets: assets,
name: [version_tag, title].join(" - "),
name: release_name,
tag_name: version_tag,
description: description,
is_draft: false,
Expand All @@ -146,5 +210,10 @@ private_lane :github do |params|
# }
# )

{
title: release_name,
description: description,
version_tag: version_tag
}
end

6 changes: 3 additions & 3 deletions fastlane/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ fastlane build

----

This README.md is auto-generated and will be re-generated every time to run [fastlane](https://fastlane.tools)
More information about fastlane can be found on [https://fastlane.tools](https://fastlane.tools).
The documentation of fastlane can be found on [GitHub](https://github.com/fastlane/fastlane)
This README.md is auto-generated and will be re-generated every time to run [fastlane](https://fastlane.tools).
More information about fastlane can be found on [https://fastlane.tools](https://fastlane.tools).
The documentation of fastlane can be found on [GitHub](https://github.com/fastlane/fastlane).
89 changes: 89 additions & 0 deletions fastlane/actions/render_github_markdown.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
module Fastlane
module Actions
module SharedValues
end

class RenderGithubMarkdownAction < Action
def self.run(params)

contents = params[:markdown_contents] || File.read(params[:markdown_file])
raise "You must pass either the markdown contents or a file path" unless contents

require 'json'
body = {
text: contents,
mode: "gfm",
context: params[:context_repository]
}.to_json

require 'base64'
headers = {
'User-Agent' => 'fastlane-render_github_markdown',
'Authorization' => "Basic #{Base64.strict_encode64(params[:api_token])}"
}

response = Excon.post("https://api.github.com/markdown", headers: headers, body: body)

raise response[:headers].to_s unless response[:status] == 200
html_markdown = response.body

ENV['RENDER_GITHUB_MARKDOWN_HTML'] = html_markdown
return html_markdown
end

#####################################################
# @!group Documentation
#####################################################

def self.description
"Uses the GitHub API to render your GitHub-flavored Markdown as HTML"
end

def self.available_options
[
FastlaneCore::ConfigItem.new(key: :markdown_file,
env_name: "FL_RENDER_GITHUB_MARKDOWN_FILE",
description: "The path to your markdown file",
optional: true,
verify_block: proc do |value|
raise "File doesn't exist '#{value}'".red unless File.exists?(value)
end),
FastlaneCore::ConfigItem.new(key: :markdown_contents,
env_name: "FL_RENDER_GITHUB_MARKDOWN_CONTENTS",
optional: true,
description: "The markdown contents"),
FastlaneCore::ConfigItem.new(key: :context_repository,
env_name: "FL_RENDER_GITHUB_MARKDOWN_CONTEXT_REPOSITORY",
description: "The path to your repo, e.g. 'fastlane/fastlane'",
verify_block: proc do |value|
raise "Please only pass the path, e.g. 'fastlane/fastlane'".red if value.include? "github.com"
raise "Please only pass the path, e.g. 'fastlane/fastlane'".red if value.split('/').count != 2
end),
FastlaneCore::ConfigItem.new(key: :api_token,
env_name: "FL_RENDER_GITHUB_MARKDOWN_API_TOKEN",
description: "Personal API Token for GitHub - generate one at https://github.com/settings/tokens",
is_string: true,
optional: false),
]
end

def self.output
[
['RENDER_GITHUB_MARKDOWN_HTML', 'Rendered HTML']
]
end

def self.return_value
"Returns the GFM Markdown contents rendered as HTML"
end

def self.authors
["czechboy0"]
end

def self.is_supported?(platform)
true
end
end
end
end
Loading

0 comments on commit 72f8b38

Please sign in to comment.