blob: 748ae39ca24a77afd5d75389a73127fb53aa4cc1 [file] [log] [blame]
Nico Huberee52fbc2023-06-24 11:52:57 +00001<?php
2
3use Gettext\Scanner\PhpScanner;
4use Gettext\Generator\PoGenerator;
5use Gettext\Translations;
6use Symfony\Component\Finder\Finder;
7
8/**
9 * This is project's console commands configuration for Robo task runner.
10 *
11 * @see http://robo.li/
12 */
13class RoboFile extends \Robo\Tasks {
14 public function xgettext() {
15 $domain = 'messages';
16
17 $finder = new Finder();
18 $finder->in('www')->name('*.php');
19
20 $translations[] = Translations::create($domain);
21
22 $scanner = new PhpScanner(...$translations);
23 $scanner->setDefaultDomain($domain);
24
25 $scanner->setFunctions(['t' => 'gettext']);
26
27 foreach ($finder as $file) {
28 $scanner->scanFile($file);
29 }
30
31 $generator = new PoGenerator();
32
33 foreach ($scanner->getTranslations() as $domain => $translations) {
34 $destFile = 'www/locale/messages.pot';
35
36 $translations->getHeaders()->set('Project-Id-Version', 'PACKAGE VERSION');
37 $translations->getHeaders()->set('Report-Msgid-Bugs-To', '');
38 $translations->getHeaders()->set('POT-Creation-Date', date('c'));
39 $translations->getHeaders()->set('PO-Revision-Date', 'YEAR-MO-DA HO:MI+ZONE');
40 $translations->getHeaders()->set('Last-Translator', 'FULL NAME <EMAIL@ADDRESS>');
41 $translations->getHeaders()->set('Language-Team', 'LANGUAGE <LL@li.org>');
42 $translations->getHeaders()->set('MIME-Version', '1.0');
43 $translations->getHeaders()->set('Content-Type', 'text/plain; charset=UTF-8');
44 $translations->getHeaders()->set('Content-Transfer-Encoding', '8bit');
45
46 $generator->generateFile($translations, $destFile);
47 }
48 }
49
50 public function build() {
51 $ref = getenv('GITHUB_REF_NAME');
52 if ($ref === false) {
53 $version = 'master';
54 } else {
55 $version = str_replace('release-', '', $ref);
56 }
57
58 $dist_file = 'simpleid-' . $version . '.tar.gz';
59
60 // 1. Set up robo collections and create temp directory
61 $main_collection = $this->collectionBuilder();
62 $prepare_collection = $this->collectionBuilder();
63 $temp = $main_collection->tmpDir();
64 $working = $main_collection->workDir("dist");
65
66 // 3. Prepare step
67 // (a) Copy files to temp directory
68 $prepare_collection->taskMirrorDir([
69 '.' => "$temp/simpleid"
70 ]);
71
72 // (b) remove unnecessary directories and files
73 $prepare_collection->taskDeleteDir([
74 "$temp/simpleid/.git",
75 "$temp/simpleid/.github",
76 "$temp/simpleid/.sourceforge",
77 "$temp/simpleid/dist",
78 "$temp/simpleid/vendor",
79 "$temp/simpleid/www/vendor",
80 "$temp/simpleid/www/test",
81 "$temp/simpleid/www/test-suite"
82 ]);
83
84 $prepare_collection->taskFileSystemStack()->remove([
85 "$temp/simpleid/www/.htaccess",
86 "$temp/simpleid/www/config.inc",
87 "$temp/simpleid/www/config.php",
88 "$temp/simpleid/www/composer.lock",
89 "$temp/simpleid/composer.lock"
90 ]);
91
92 // (c) run
93 $result = $prepare_collection->run();
94 if (!$result->wasSuccessful()) {
95 return $result;
96 }
97
98 // 4. Replace variables
99 $finder = new Finder();
100 $finder->in("$temp/simpleid/www")->name('*.php')->name('*.dist');
101 foreach($finder as $file) {
102 $main_collection->taskReplaceInFile($file)
103 ->from(['@@BUILD_VERSION@@', '@@IDENTITIES_DIR@@', '@@CACHE_DIR@@', '@@STORE_DIR@@'])
104 ->to([$version, '../identities', '../cache', '../store']);
105 }
106
107 // 5. Create the release files
108 $main_collection->taskFileSystemStack()->mkdir("$working/$version")->copy('.sourceforge/frs/README.md', "$working/$version/README.md");
109 $main_collection->taskPack("$working/$version/$dist_file")->addDir('simpleid/', "$temp/simpleid");
Nico Huber097e9e22023-07-21 14:26:07 +0000110 $main_collection->taskWriteToFile('version.txt')->text($version);
Nico Huberee52fbc2023-06-24 11:52:57 +0000111
112 // 6. Run everything
113 return $main_collection->run();
114 }
115}