Skip to content

Commit

Permalink
fix(appimage): Several updates required to get JReleaser's appimage i…
Browse files Browse the repository at this point in the history
…n shape
  • Loading branch information
aalmiray committed Aug 13, 2022
1 parent 54f1cce commit e80c1ec
Show file tree
Hide file tree
Showing 31 changed files with 328 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
return templates;
}

private static BufferedReader newBufferedReader(Path file) throws IOException {
return new BufferedReader(new InputStreamReader(new FileInputStream(file.toFile()), StandardCharsets.UTF_8));
private static Reader newBufferedReader(Path file) throws IOException {
return new InputStreamReader(new FileInputStream(file.toFile()), StandardCharsets.UTF_8);
}

public static Map<String, Reader> resolveTemplates(JReleaserLogger logger, String distributionType, String toolName, boolean snapshot) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ native-image.chocolatey=binary.nuspec.tpl,tools/chocolateyinstall.ps1.tpl,.githu
native-image.docker=Dockerfile.tpl,Dockerfile-remote.tpl
native-image.gofish=food.lua.tpl
native-image.macports=Portfile.tpl
native-image.scoop=README.md.tpl,manifest.json.tplnative-package
native-image.scoop=README.md.tpl,manifest.json.tpl
native-image.snap=README.md.tpl,snap/snapcraft.yaml.tpl
native-image.spec=app.spec.tpl
native-package.brew=cask.rb.tpl,README.md.tpl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Name={{projectNameCapitalized}}
Exec={{distributionExecutableName}}
Icon={{distributionExecutableName}}
Categories={{appImageCategory}}
Categories={{appImageCategoriesByComma}}
Terminal=true
Type=Application
Version=1.0
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@
<screenshots>
{{#appImageScreenshots}}
<screenshot{{#primary}} type="default"{{/primary}}>
<type>{{type}}</type>
<image>{{url}}</image>
{{#caption}}<caption>{{caption}}</caption>{{/caption}}
{{#width}}<width>{{width}}</width>{{/width}}
{{#height}}<height>{{height}}</height>{{/height}}
<image type="{{type}}"{{#width}} width="{{width}}"{{/width}}{{#height}} height="{{height}}"{{/height}}>{{url}}</image>
</screenshot>
{{/appImageScreenshots}}
</screenshots>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Name={{projectNameCapitalized}}
Exec={{distributionExecutableName}}
Icon={{distributionExecutableName}}
Categories={{appImageCategory}}
Categories={{appImageCategoriesByComma}}
Terminal={{appImageRequiresTerminal}}
Type=Application
Version=1.0
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,8 @@
<screenshots>
{{#appImageScreenshots}}
<screenshot{{#primary}} type="default"{{/primary}}>
<type>{{type}}</type>
<image>{{url}}</image>
{{#caption}}<caption>{{caption}}</caption>{{/caption}}
{{#width}}<width>{{width}}</width>{{/width}}
{{#height}}<height>{{height}}</height>{{/height}}
<image type="{{type}}"{{#width}} width="{{width}}"{{/width}}{{#height}} height="{{height}}"{{/height}}>{{url}}</image>
</screenshot>
{{/appImageScreenshots}}
</screenshots>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Name={{projectNameCapitalized}}
Exec={{distributionExecutableName}}
Icon={{distributionExecutableName}}
Categories={{appImageCategory}}
Categories={{appImageCategoriesByComma}}
Terminal=true
Type=Application
Version=1.0
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@
<screenshots>
{{#appImageScreenshots}}
<screenshot{{#primary}} type="default"{{/primary}}>
<type>{{type}}</type>
<image>{{url}}</image>
{{#caption}}<caption>{{caption}}</caption>{{/caption}}
{{#width}}<width>{{width}}</width>{{/width}}
{{#height}}<height>{{height}}</height>{{/height}}
<image type="{{type}}"{{#width}} width="{{width}}"{{/width}}{{#height}} height="{{height}}"{{/height}}>{{url}}</image>
</screenshot>
{{/appImageScreenshots}}
</screenshots>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Name={{projectNameCapitalized}}
Exec={{distributionExecutableName}}
Icon={{distributionExecutableName}}
Categories={{appImageCategory}}
Categories={{appImageCategoriesByComma}}
Terminal={{appImageRequiresTerminal}}
Type=Application
Version=1.0
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,8 @@
<screenshots>
{{#appImageScreenshots}}
<screenshot{{#primary}} type="default"{{/primary}}>
<type>{{type}}</type>
<image>{{url}}</image>
{{#caption}}<caption>{{caption}}</caption>{{/caption}}
{{#width}}<width>{{width}}</width>{{/width}}
{{#height}}<height>{{height}}</height>{{/height}}
<image type="{{type}}"{{#width}} width="{{width}}"{{/width}}{{#height}} height="{{height}}"{{/height}}>{{url}}</image>
</screenshot>
{{/appImageScreenshots}}
</screenshots>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Name={{projectNameCapitalized}}
Exec={{distributionExecutableName}}
Icon={{distributionExecutableName}}
Categories={{appImageCategory}}
Categories={{appImageCategoriesByComma}}
Terminal=true
Type=Application
Version=1.0
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@
<screenshots>
{{#appImageScreenshots}}
<screenshot{{#primary}} type="default"{{/primary}}>
<type>{{type}}</type>
<image>{{url}}</image>
{{#caption}}<caption>{{caption}}</caption>{{/caption}}
{{#width}}<width>{{width}}</width>{{/width}}
{{#height}}<height>{{height}}</height>{{/height}}
<image type="{{type}}"{{#width}} width="{{width}}"{{/width}}{{#height}} height="{{height}}"{{/height}}>{{url}}</image>
</screenshot>
{{/appImageScreenshots}}
</screenshots>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Name={{projectNameCapitalized}}
Exec={{distributionExecutableName}}
Icon={{distributionExecutableName}}
Categories={{appImageCategory}}
Categories={{appImageCategoriesByComma}}
Terminal={{appImageRequiresTerminal}}
Type=Application
Version=1.0
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,8 @@
<screenshots>
{{#appImageScreenshots}}
<screenshot{{#primary}} type="default"{{/primary}}>
<type>{{type}}</type>
<image>{{url}}</image>
{{#caption}}<caption>{{caption}}</caption>{{/caption}}
{{#width}}<width>{{width}}</width>{{/width}}
{{#height}}<height>{{height}}</height>{{/height}}
<image type="{{type}}"{{#width}} width="{{width}}"{{/width}}{{#height}} height="{{height}}"{{/height}}>{{url}}</image>
</screenshot>
{{/appImageScreenshots}}
</screenshots>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Name={{projectNameCapitalized}}
Exec={{distributionExecutableName}}
Icon={{distributionExecutableName}}
Categories={{appImageCategory}}
Categories={{appImageCategoriesByComma}}
Terminal=true
Type=Application
Version=1.0
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@
<screenshots>
{{#appImageScreenshots}}
<screenshot{{#primary}} type="default"{{/primary}}>
<type>{{type}}</type>
<image>{{url}}</image>
{{#caption}}<caption>{{caption}}</caption>{{/caption}}
{{#width}}<width>{{width}}</width>{{/width}}
{{#height}}<height>{{height}}</height>{{/height}}
<image type="{{type}}"{{#width}} width="{{width}}"{{/width}}{{#height}} height="{{height}}"{{/height}}>{{url}}</image>
</screenshot>
{{/appImageScreenshots}}
</screenshots>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Name={{projectNameCapitalized}}
Exec={{distributionExecutableName}}
Icon={{distributionExecutableName}}
Categories={{appImageCategory}}
Categories={{appImageCategoriesByComma}}
Terminal={{appImageRequiresTerminal}}
Type=Application
Version=1.0
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,8 @@
<screenshots>
{{#appImageScreenshots}}
<screenshot{{#primary}} type="default"{{/primary}}>
<type>{{type}}</type>
<image>{{url}}</image>
{{#caption}}<caption>{{caption}}</caption>{{/caption}}
{{#width}}<width>{{width}}</width>{{/width}}
{{#height}}<height>{{height}}</height>{{/height}}
<image type="{{type}}"{{#width}} width="{{width}}"{{/width}}{{#height}} height="{{height}}"{{/height}}>{{url}}</image>
</screenshot>
{{/appImageScreenshots}}
</screenshots>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ protected void doPrepareDistribution(Distribution distribution,
writeFile(context.getModel().getProject(), distribution, content, props, prepareDirectory, filename);
} else {
context.getLogger().debug(RB.$("packager.write.file"), filename, distributionName, packagerName);
writeFile(entry.getValue(), prepareDirectory.resolve(filename));
writeFile(context.getModel().getProject(), distribution, entry.getValue(), props, prepareDirectory, filename);
}
}

Expand Down Expand Up @@ -147,6 +147,10 @@ protected void doPackageDistribution(Distribution distribution, Map<String, Obje

protected abstract void writeFile(Project project, Distribution distribution, String content, Map<String, Object> props, Path outputDirectory, String fileName) throws PackagerProcessingException;

protected void writeFile(Project project, Distribution distribution, Reader reader, Map<String, Object> props, Path outputDirectory, String fileName) throws PackagerProcessingException {
writeFile(reader, outputDirectory.resolve(fileName));
}

protected void writeFile(Reader reader, Path outputFile) throws PackagerProcessingException {
try {
createDirectoriesWithFullAccess(outputFile.getParent());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.jreleaser.model.packager.spi.PackagerProcessingException;

import java.io.IOException;
import java.io.Reader;
import java.nio.file.Path;
import java.text.SimpleDateFormat;
import java.util.Date;
Expand All @@ -39,6 +40,7 @@
import static java.util.stream.Collectors.toList;
import static org.jreleaser.templates.TemplateUtils.trimTplExtension;
import static org.jreleaser.util.Constants.KEY_APPIMAGE_CATEGORIES;
import static org.jreleaser.util.Constants.KEY_APPIMAGE_CATEGORIES_BY_COMMA;
import static org.jreleaser.util.Constants.KEY_APPIMAGE_COMPONENT_ID;
import static org.jreleaser.util.Constants.KEY_APPIMAGE_DEVELOPER_NAME;
import static org.jreleaser.util.Constants.KEY_APPIMAGE_DISTRIBUTION_ARTIFACT_FILE;
Expand Down Expand Up @@ -76,6 +78,7 @@ protected void fillPackagerProperties(Map<String, Object> props, Distribution di
props.put(KEY_APPIMAGE_URLS, context.getModel().getProject().getLinks().asAppdataLinks());
props.put(KEY_APPIMAGE_COMPONENT_ID, getPackager().getComponentId());
props.put(KEY_APPIMAGE_CATEGORIES, getPackager().getCategories());
props.put(KEY_APPIMAGE_CATEGORIES_BY_COMMA, String.join(",", getPackager().getCategories()));
props.put(KEY_APPIMAGE_DEVELOPER_NAME, getPackager().getDeveloperName());
props.put(KEY_APPIMAGE_REQUIRES_TERMINAL, getPackager().isRequiresTerminal());
props.put(KEY_APPIMAGE_REPO_OWNER, packager.getRepository().getOwner());
Expand All @@ -89,7 +92,7 @@ protected void fillPackagerProperties(Map<String, Object> props, Distribution di
str = str.replace(context.getModel().getProject().getEffectiveVersion(), "${DISTRIBUTION_VERSION}");
props.put(KEY_APPIMAGE_DISTRIBUTION_ARTIFACT_FILE_NAME, str);
str = (String) props.get(KEY_DISTRIBUTION_URL);
str = str.replace(gitService.getResolvedTagName(context.getModel()), "${DISTRIBUTION_TAG}")
str = str.replace(gitService.getEffectiveTagName(context.getModel()), "${DISTRIBUTION_TAG}")
.replace((String) props.get(KEY_DISTRIBUTION_ARTIFACT_FILE), "${DISTRIBUTION_FILE}");
props.put(KEY_APPIMAGE_DISTRIBUTION_URL, str);

Expand Down Expand Up @@ -135,7 +138,7 @@ protected void writeFile(Project project,

Path outputFile = outputDirectory.resolve(fileName);

if ("app.desktop".equals(fileName) || "icons/app.png".equals(fileName)) {
if ("app.desktop".equals(fileName)) {
outputFile = outputDirectory.resolve(fileName.replace("app", distribution.getExecutable().getName()));
} else if ("appdata.xml".equals(fileName)) {
outputFile = outputDirectory.resolve(getPackager().getComponentId() + ".appdata.xml");
Expand All @@ -144,6 +147,16 @@ protected void writeFile(Project project,
writeFile(content, outputFile);
}

protected void writeFile(Project project, Distribution distribution, Reader reader, Map<String, Object> props, Path outputDirectory, String fileName) throws PackagerProcessingException {
Path outputFile = outputDirectory.resolve(fileName);

if (fileName.endsWith("app.png")) {
outputFile = outputDirectory.resolve(fileName.replace("app", distribution.getExecutable().getName()));
}

writeFile(reader, outputFile);
}

private Optional<Stereotype> resolveStereotype(String fileName) {
for (Stereotype stereotype : packager.getSupportedStereotypes()) {
if (fileName.startsWith(stereotype.toString() + "-")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ public interface Constants {
String KEY_APPIMAGE_REPO_NAME = "appImageRepoName";
String KEY_APPIMAGE_COMPONENT_ID = "appImageComponentId";
String KEY_APPIMAGE_CATEGORIES = "appImageCategories";
String KEY_APPIMAGE_CATEGORIES_BY_COMMA = "appImageCategoriesByComma";
String KEY_APPIMAGE_DEVELOPER_NAME = "appImageDeveloperName";
String KEY_APPIMAGE_REQUIRES_TERMINAL = "appImageRequiresTerminal";
String KEY_APPIMAGE_RELEASES = "appImageReleases";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Release

on:
push:
tags:
- '*'

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Variables
id: vars
run: |
echo ::set-output name=version::$(cat VERSION)
echo ::set-output name=tag::${GITHUB_REF#refs/tags/}

- name: Create the AppImage
run: sh create-appimage.sh
env:
DISTRIBUTION_VERSION: ${{=<% %>=}}{{ steps.vars.outputs.version }}<%={{ }}=%>
DISTRIBUTION_TAG: ${{=<% %>=}}{{ steps.vars.outputs.tag }}<%={{ }}=%>

- name: Release
uses: jreleaser/release-action@v2
with:
version: latest
arguments: full-release
env:
JRELEASER_PROJECT_VERSION: ${{=<% %>=}}{{ steps.vars.outputs.version }}<%={{ }}=%>
JRELEASER_GITHUB_TOKEN: ${{=<% %>=}}{{ secrets.GITHUB_TOKEN }}<%={{ }}=%>
JRELEASER_GPG_PASSPHRASE: ${{=<% %>=}}{{ secrets.GPG_PASSPHRASE }}<%={{ }}=%>
JRELEASER_GPG_PUBLIC_KEY: ${{=<% %>=}}{{ secrets.GPG_PUBLIC_KEY }}<%={{ }}=%>
JRELEASER_GPG_SECRET_KEY: ${{=<% %>=}}{{ secrets.GPG_SECRET_KEY }}<%={{ }}=%>
JRELEASER_TWITTER_CONSUMER_KEY: ${{=<% %>=}}{{ secrets.TWITTER_CONSUMER_KEY }}<%={{ }}=%>
JRELEASER_TWITTER_CONSUMER_SECRET: ${{=<% %>=}}{{ secrets.TWITTER_CONSUMER_SECRET }}<%={{ }}=%>
JRELEASER_TWITTER_ACCESS_TOKEN: ${{=<% %>=}}{{ secrets.TWITTER_ACCESS_TOKEN }}<%={{ }}=%>
JRELEASER_TWITTER_ACCESS_TOKEN_SECRET: ${{=<% %>=}}{{ secrets.TWITTER_ACCESS_TOKEN_SECRET }}<%={{ }}=%>

- name: JReleaser output
if: always()
uses: actions/upload-artifact@v3
with:
name: jreleaser-logs
path: |
out/jreleaser/trace.log
out/jreleaser/output.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
= AppImage for JReleaser

:linkattrs:
:executable: {{distributionExecutableName}}
:project-owner: {{appImageRepoOwner}}
:project-name: {{appImageRepoName}}
:project-version: {{projectVersion}}
:project-tag: {{tagName}}

image:https://img.shields.io/github/workflow/status/{project-owner}/{project-name}/Release?logo=github["Build Status", link="https://github.com/{project-owner}/{project-name}/actions"]
image:https://img.shields.io/github/downloads/{project-owner}/{project-name}/total[GitHub Release Total]

---

Follow these instructions to run JReleaser as an AppImage:

* Download the latest AppImage from the release page

[source]
[subs="attributes"]
----
$ curl https://github.com/{project-owner}/{project-name}/releases/download/{project-tag}/{executable}-{project-version}-x86_64.AppImage --output {executable}
----

* Make it executable

[source]
[subs="attributes"]
----
$ chmod +x {executable}
----

* Run it

[source]
[subs="attributes"]
----
$ ./{executable} --help
----
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{projectVersion}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Desktop Entry]
Name=JReleaser
Exec={{distributionExecutableName}}
Icon={{distributionExecutableName}}
Categories={{appImageCategoriesByComma}}
Terminal=true
Type=Application
Version=1.0

0 comments on commit e80c1ec

Please sign in to comment.