Skip to content

Commit

Permalink
Adding homebrew build
Browse files Browse the repository at this point in the history
  • Loading branch information
kebernet committed Jul 31, 2024
1 parent d85b794 commit 59b62f8
Show file tree
Hide file tree
Showing 22 changed files with 960 additions and 578 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/deploy-homebrew.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
set -x
set -e
cd target
CLONE_DIRECTORY=homebrew

git config --global user.email "$COMMIT_EMAIL"
git config --global user.name "$COMMIT_USERNAME"

git clone --single-branch --branch "$DESTINATION_BRANCH" "https://$API_TOKEN_GITHUB@github.com/$DESTINATION_REPOSITORY.git" "$CLONE_DIRECTORY"
ls -la "$CLONE_DIRECTORY"

mkdir -p "$CLONE_DIRECTORY/$DESTINATION_DIRECTORY"
cd ..

cp -rvf $SOURCE_FILES "target/$CLONE_DIRECTORY/$DESTINATION_DIRECTORY"

cd target/$CLONE_DIRECTORY
git add .
git status

git diff-index --quiet HEAD || git commit --message "$COMMIT_MESSAGE"
git config --unset-all "http.https://github.com/.extraheader" || echo "Failed"
git push origin --set-upstream "$DESTINATION_BRANCH"
31 changes: 30 additions & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,18 @@ jobs:
steps:
- name: Checkout Code
uses: actions/checkout@v3
- uses: graalvm/setup-graalvm@v1
with:
java-version: '22'
distribution: 'graalvm'
github-token: ${{ github.token }}
- run: java -version && uname -a
- name: Set Version
run: |
./mvnw -U --batch-mode versions:set dependency:tree -DnewVersion=${{ needs.project-info.outputs.PROJECT_VERSION }}
- name: Download Artifacts
uses: actions/checkout@v3
- name: Download All Artifacts
uses: actions/download-artifact@v4
with:
Expand Down Expand Up @@ -276,4 +288,21 @@ jobs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./target/GitHub Actions Notifier-${{ needs.project-info.outputs.PROJECT_VERSION }}.msi
asset_name: GitHub Actions Notifier-${{ needs.project-info.outputs.PROJECT_VERSION }}.msi
asset_content_type: application/octet-stream
asset_content_type: application/octet-stream
- name: Build Homebrew Formula
run: |
wget https://github.com/atl-tw/${{ needs.project-info.outputs.PROJECT_ARTIFACT }}/archive/refs/tags/${{ needs.project-info.outputs.PROJECT_VERSION }}.zip
ZIP_SHA=$(shasum -a 256 ${{ needs.project-info.outputs.PROJECT_VERSION }}.zip | awk '{print $1}')
./mvnw -s "-Dbrew.asset.url=https://github.com/atl-tw/${{ needs.project-info.outputs.PROJECT_ARTIFACT }}/archive/refs/tags/${{ needs.project-info.outputs.PROJECT_VERSION }}.zip" -Dbrew.asset.hash=$ZIP_SHA --batch-mode package
- name: Publish Homebrew
env:
DESTINATION_BRANCH: main
DESTINATION_REPOSITORY: 'atl-tw/homebrew-tap'
API_TOKEN_GITHUB: ${{ secrets.MAVEN_TOKEN }}
COMMIT_EMAIL: rcooper@thoughtworks.com
COMMIT_USERNAME: ${{secrets.MAVEN_USER}}
COMMIT_MESSAGE: "Updating ${{ needs.project-info.outputs.PROJECT_ARTIFACT }} to -${{ needs.project-info.outputs.PROJECT_VERSION }}"
SOURCE_FILES: 'target/brew/${{ needs.project-info.outputs.PROJECT_ARTIFACT }}/*'
DESTINATION_DIRECTORY: ''
run: |
.github/workflows/deploy-homebrew.sh
165 changes: 134 additions & 31 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
<version>1.0-SNAPSHOT</version>
<name>gha-notifier</name>
<url>https://github.com/atl-tw/gha-notifier</url>
<description>A desktop notifier for GitHub actions that delegates to the gh command line.</description>
<properties>
<java.version>17</java.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<junit.version>5.10.2</junit.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mainClassName>com.thoughtworks.gha.notifier.GitHubNotifier</mainClassName>
</properties>
Expand Down Expand Up @@ -64,9 +66,30 @@
<version>3.6</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.8.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
<version>1.1.3</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down Expand Up @@ -94,6 +117,108 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>maven-replacer-plugin</artifactId>
<version>1.3.5</version>
<executions>
<execution>
<id>prepare-formula</id>
<goals>
<goal>replace</goal>
</goals>
<configuration>
<file>src/main/brew/Formula.rb</file>
<outputFile>
target/brew/${project.artifactId}/Formula/${project.artifactId}.rb
</outputFile>
<replacements>
<replacement>
<token>@artifactId@</token>
<value>${project.artifactId}</value>
</replacement>
<replacement>
<token>@version@</token>
<value>${project.version}</value>
</replacement>
<replacement>
<!--suppress UnresolvedMavenProperty -->
<token>@asseturl@</token>
<value>${brew.asset.url}</value>
</replacement>
<replacement>
<!--suppress UnresolvedMavenProperty -->
<token>@assethash@</token>
<value>${brew.asset.hash}</value>
</replacement>
<replacement>
<!--suppress UnresolvedMavenProperty -->
<token>@name@</token>
<value>${brew.formula.name}</value>
</replacement>
<replacement>
<!--suppress UnresolvedMavenProperty -->
<token>@description@</token>
<value>${project.description}</value>
</replacement>
<replacement>
<!--suppress UnresolvedMavenProperty -->
<token>@homepage@</token>
<value>${project.url}</value>
</replacement>
</replacements>
</configuration>
</execution>
<execution>
<id>prepare-versioned-formula</id>
<goals>
<goal>replace</goal>
</goals>
<configuration>
<file>src/main/brew/Formula.rb</file>
<outputFile>
target/brew/${project.artifactId}/Formula/${project.artifactId}@${project.version}.rb
</outputFile>
<replacements>
<replacement>
<token>@artifactId@</token>
<value>${project.artifactId}</value>
</replacement>
<replacement>
<token>@version@</token>
<value>${project.version}</value>
</replacement>
<replacement>
<!--suppress UnresolvedMavenProperty -->
<token>@asseturl@</token>
<value>${brew.asset.url}</value>
</replacement>
<replacement>
<!--suppress UnresolvedMavenProperty -->
<token>@assethash@</token>
<value>${brew.asset.hash}</value>
</replacement>
<replacement>
<!--suppress UnresolvedMavenProperty -->
<token>@name@</token>
<value>${brew.formula.name}</value>
</replacement>
<replacement>
<!--suppress UnresolvedMavenProperty -->
<token>@description@</token>
<value>${project.description}</value>
</replacement>
<replacement>
<!--suppress UnresolvedMavenProperty -->
<token>@homepage@</token>
<value>${project.url}</value>
</replacement>
</replacements>
</configuration>
</execution>
</executions>

</plugin>
</plugins>
</build>

Expand Down Expand Up @@ -260,54 +385,31 @@
</build>
</profile>
<profile>
<id>mac-intel</id>
<id>mac-noarch</id>
<build>
<plugins>
<plugin>
<groupId>com.googlecode.maven-download-plugin</groupId>
<artifactId>download-maven-plugin</artifactId>
<version>1.9.0</version>
<executions>
<execution>
<id>download-jre</id>
<phase>prepare-package</phase>
<goals>
<goal>wget</goal>
</goals>
</execution>
</executions>
<configuration>
<url>https://download.bell-sw.com/java/17.0.12+10/bellsoft-jre17.0.12+10-macos-amd64.zip</url>
<unpack>true</unpack>
<outputDirectory>${project.build.directory}/jre-17</outputDirectory>
</configuration>
</plugin>
<!-- We are not using JPackage for Mac OS because this plugin allows us to bundle for any architecture -->
<plugin>
<groupId>de.perdian.maven.plugins</groupId>
<artifactId>macosappbundler-maven-plugin</artifactId>
<version>1.20.1</version>
<configuration>
<nativeBinary>X86_64</nativeBinary>
<plist>
<CFBundleName>GitHub Actions Notifier</CFBundleName>
<CFBundleIconFile>src/bundle/icon.icns</CFBundleIconFile>
<JVMMainClassName>${mainClassName}</JVMMainClassName>
<CFBundleDisplayName>GitHub Actions Notifier</CFBundleDisplayName>
<CFBundleDevelopmentRegion>English</CFBundleDevelopmentRegion>
<JVMRuntimePath>${jvmRuntimePath}</JVMRuntimePath>
<CFBundleURLTypes>
<string>msa</string>
</CFBundleURLTypes>
<JVMVersion>17+</JVMVersion>
</plist>
<dmg>
<generate>true</generate>
<dmgFileName>gha-notifier-x86_64</dmgFileName>
<generate>false</generate>
</dmg>
<jdk>
<include>true</include>
<location>${project.build.directory}/jre-17/jre-17.0.12.jre</location>
</jdk>


</configuration>
<executions>
<execution>
Expand All @@ -321,5 +423,6 @@
</plugins>
</build>
</profile>

</profiles>
</project>
17 changes: 17 additions & 0 deletions src/main/brew/Formula.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require "formula"

class @name@ < Formula
desc '@description@'
homepage '@homepage@'
url "@asseturl@"
sha256 "@assethash@"
version '@version@'

depends_on 'openjdk@17'

def install
jreRuntimePath = Formula["openjdk@17"].opt_prefix + "/libexec/openjdk.jdk/Contents/Home"
system "./mvnw", "-Pmac-noarch" "package", "-DskipTests" "-DjreRuntimePath"+jreRuntimePath
(prefix/"Applications").install "target/GitHub Actions Notifier.app"
end
end
12 changes: 6 additions & 6 deletions src/main/java/com/thoughtworks/gha/notifier/GitHubNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import com.thoughtworks.gha.notifier.controller.ConfigurationController;
import com.thoughtworks.gha.notifier.service.MonitorService;
import com.thoughtworks.gha.notifier.util.SystemUtil;
import com.thoughtworks.gha.notifier.view.ConfigurationWindow;
import com.thoughtworks.gha.notifier.view.Toaster;
import com.thoughtworks.gha.notifier.view.Tray;
import com.thoughtworks.gha.notifier.view.impl.ConfigurationWindowImpl;
import com.thoughtworks.gha.notifier.view.impl.ToasterImpl;
import com.thoughtworks.gha.notifier.view.impl.TrayImpl;
import javafx.embed.swing.JFXPanel;

import javax.swing.*;
Expand All @@ -29,12 +29,12 @@ public class GitHubNotifier {

private GitHubNotifier() {
MonitorService monitorService = new MonitorService();
ConfigurationWindow configurationWindow = new ConfigurationWindow();
ConfigurationWindowImpl configurationWindow = new ConfigurationWindowImpl();
if (!monitorService.checkGitHub()) {
configurationWindow.showMessageDialog("GitHub CLI not found. Please select the GitHub icon and locate it on your system.");
}
Toaster toaster = new Toaster();
Tray tray = new Tray();
ToasterImpl toaster = new ToasterImpl();
TrayImpl tray = new TrayImpl();
this.controller = new ConfigurationController(monitorService, configurationWindow, tray, toaster);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import java.beans.PropertyChangeEvent;
import java.util.Set;
import java.util.List;

import static java.util.Optional.ofNullable;

Expand All @@ -20,7 +21,7 @@ public class ConfigurationController {
private final Tray tray;
private final Toaster toaster;

private java.util.List<Workflow> selectedWorkflows;
private List<Workflow> selectedWorkflows;
public ConfigurationController(MonitorService configurationService, ConfigurationWindow configurationWindow, Tray tray, Toaster toaster) {
this.monitorService = configurationService;
this.configurationWindow = configurationWindow;
Expand Down Expand Up @@ -82,7 +83,7 @@ private void onAddRepository() {
}

private void onRemoveRepositories() {
var selected = configurationWindow.getMainForm().getSelectedResponsitories();
var selected = configurationWindow.getMainForm().getSelectedRepositories();
monitorService.removeRepositories(selected);
}

Expand All @@ -96,7 +97,7 @@ private void onWorkflowSelected() {
}
configurationWindow.getMainForm().showWorkflowConfig();
var notify = selected.stream().map(monitorService::workflowNotified).reduce((a, b) -> a || b).orElse(false);
configurationWindow.getMainForm().setNotify(notify);
configurationWindow.getMainForm().setNotifyChecked(notify);
if (selected.size() == 1) {
configurationWindow.getMainForm().setOnMainBranchChanged(this::onMainBranchChanged);
configurationWindow.getMainForm().setMainBranch(selected.get(0).getMainBranch());
Expand All @@ -115,7 +116,7 @@ private void onGitHubSelect() {
}

private void onRepositoriesSelected() {
var selected = configurationWindow.getMainForm().getSelectedResponsitories();
var selected = configurationWindow.getMainForm().getSelectedRepositories();
if (selected == null || selected.size() != 1) {
configurationWindow.getMainForm().hideDetailsPane();
return;
Expand Down
Loading

0 comments on commit 59b62f8

Please sign in to comment.