Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
osx-release 12.15 KiB
#! /usr/bin/perl -I./bin

use strict;
use warnings;

use Cwd 'getcwd';
use File::Copy 'copy';
use File::Copy::Recursive 'rcopy';   # CPAN
use File::Path 'remove_tree';
use File::stat 'stat';
use JSON 'encode_json', 'from_json'; # CPAN
use Readonly;                        # CPAN
use String::Util 'trim';             # CPAN
use Text::Caml;                      # CPAN
use WWW::Curl::Simple;               # CPAN

use Metabase::Util;

Readonly my $app             => artifact('Metabase.app');
Readonly my $zipfile         => artifact('Metabase.zip');
Readonly my $appcast         => artifact('appcast.xml');
Readonly my $release_notes   => artifact('release-notes.html');
Readonly my $dmg             => artifact('Metabase.dmg');

Readonly my $xcode_project   => get_file_or_die('OSX/Metabase.xcodeproj');

# Get the version saved in the CFBundle, e.g. '0.11.3.1'
sub version {
    return trim(plist_buddy_exec('Print', 'CFBundleVersion'));
}

# Get the tag saved in version.properties, e.g. '0.12.0'
sub version_from_props_file {
  open(FILE, get_file_or_die('resources/version.properties')) or die $!;
  while (<FILE>) { m/^tag/ && s/^tag=v([0-9.]+)[^0-9.]*$/$1/ && (return trim($_)); };
}

# This is the name of the subdirectory on s3, e.g. 'v.0.12.0'
sub upload_subdir {
  return 'v' . version_from_props_file();
}

# Next version after version(), e.g. '0.11.3.2'
sub next_version {
    my ($old_version_tag, $old_version_point_release) = (version() =~ /^(\d+\.\d+\.\d+)\.(\d+)$/);

    Readonly my $tag_from_props_file => version_from_props_file();

    # Now calculate the new version, which is ($tag.$point_release)
    # Check and see if tag has changed in version.properties; if so, new version is the first "point release" of that tag.
    return $old_version_tag eq $tag_from_props_file ? ($old_version_tag . '.' . ($old_version_point_release + 1)) : "$tag_from_props_file.0";
}

sub bump_version {
    Readonly my $new_version => next_version();
    announce 'Bumping version: ' . version() . " -> $new_version";

    plist_buddy_exec('Set', ':CFBundleVersion', $new_version);
    plist_buddy_exec('Set', ':CFBundleShortVersionString', $new_version);
}

sub clean {
    system('xcodebuild', 'clean', '-project', $xcode_project) == 0 or die $!;
    remove_tree(OSX_ARTIFACTS_DIR);
}

# Build Metabase.app
sub build {
    announce "Building $app...";