ci: reduce dist sizes and build MacOS ARM dist #580
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions | |
name: Build | |
on: | |
push: | |
branches-ignore: # build all branches except: | |
- 'dependabot/**' # prevent GHA triggered twice (once for commit to the branch and once for opening/syncing the PR) | |
tags-ignore: # don't build tags | |
- '**' | |
paths-ignore: | |
- '**/*.adoc' | |
- '**/*.md' | |
- '.editorconfig' | |
- '.git*' | |
- '.github/*.yml' | |
- '.github/workflows/stale.yml' | |
pull_request: | |
paths-ignore: | |
- '**/*.adoc' | |
- '**/*.md' | |
- '.editorconfig' | |
- '.git*' | |
- '.github/*.yml' | |
repository_dispatch: | |
types: [new-haxe4e-release] | |
workflow_dispatch: | |
# https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/ | |
inputs: | |
additional_maven_args: | |
description: 'Additional Maven Args' | |
required: false | |
default: '' | |
defaults: | |
run: | |
shell: bash | |
env: | |
JAVA_VERSION: 17 | |
jobs: | |
########################################################### | |
maven-build: | |
########################################################### | |
runs-on: windows-latest | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: ${{ github.event_name == 'repository_dispatch' }} | |
steps: | |
- name: "Show: GitHub context" | |
env: | |
GITHUB_CONTEXT: ${{ toJSON(github) }} | |
run: echo $GITHUB_CONTEXT | |
- name: "Show: environment variables" | |
run: env | sort | |
- name: Git Checkout | |
uses: actions/checkout@v4 # https://github.com/actions/checkout | |
- name: "Install: JDK ${{ env.JAVA_VERSION }} ☕" | |
uses: actions/setup-java@v4 # https://github.com/actions/setup-java | |
with: | |
distribution: temurin | |
java-version: ${{ env.JAVA_VERSION }} | |
- name: "Cache: Local Maven Repository" | |
uses: actions/cache@v4 | |
with: | |
# Excluded sub directory not working https://github.com/actions/toolkit/issues/713 | |
path: | | |
~/.m2/repository/* | |
!~/.m2/repository/com/vegardit/no-npe | |
!~/.m2/repository/.cache/tycho | |
!~/.m2/repository/.meta/p2-artifacts.properties | |
!~/.m2/repository/p2 | |
!~/.m2/repository/*SNAPSHOT* | |
key: ${{ runner.os }}-repo-mvn-${{ hashFiles('**/pom.xml') }} | |
- name: "Cache: Local Tycho Repository" | |
uses: actions/cache@v4 | |
with: | |
path: | | |
~/.m2/repository/.cache/tycho | |
~/.m2/repository/.meta/p2-artifacts.properties | |
~/.m2/repository/p2 | |
key: ${{ runner.os }}-repo-tycho-${{ hashFiles('build.target') }} | |
- name: "Build with Maven 🔨" | |
id: maven-build | |
env: | |
GITHUB_USER: ${{ github.actor }} | |
GITHUB_API_KEY: ${{ github.token }} | |
run: | | |
set -eu | |
# | |
# ensure mnvw is executable | |
# | |
chmod u+x ./mvnw | |
# https://github.community/t/github-actions-bot-email-address/17204 | |
git config user.name "github-actions[bot]" | |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
MAVEN_OPTS="${MAVEN_OPTS:-}" | |
MAVEN_OPTS+=" -Djava.security.egd=file:/dev/./urandom" # https://stackoverflow.com/questions/58991966/what-java-security-egd-option-is-for/59097932#59097932 | |
MAVEN_OPTS+=" -Dorg.slf4j.simpleLogger.showDateTime=true -Dorg.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss,SSS" # https://stackoverflow.com/questions/5120470/how-to-time-the-different-stages-of-maven-execution/49494561#49494561 | |
MAVEN_OPTS+=" -Xmx1024m -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Dhttps.protocols=TLSv1.3,TLSv1.2" | |
export MAVEN_OPTS | |
echo "MAVEN_OPTS: $MAVEN_OPTS" | |
./mvnw \ | |
--errors \ | |
--update-snapshots \ | |
--batch-mode \ | |
--show-version \ | |
--no-transfer-progress \ | |
-s .ci/maven-settings.xml \ | |
-t .ci/maven-toolchains.xml \ | |
-Dtycho.disableP2Mirrors=true \ | |
${{ github.event.inputs.additional_maven_args }} \ | |
clean verify | |
cd product/target/products | |
# remove unused dynamic libs | |
rm -rf \ | |
org.haxe4e.studio/linux/gtk/x86_64/plugins/com.sun.jna_*/com/sun/jna/{aix,darwin,freebsd,linux-a,linux-l,linux-m,linux-p,linux-r,linux-s,openbsd,sunos,win32}* \ | |
org.haxe4e.studio/macosx/cocoa/x86_64/Eclipse.app/Contents/Eclipse/plugins/com.sun.jna_*/com/sun/jna/{aix,freebsd,linux,openbsd,sunos,win32}* \ | |
org.haxe4e.studio/win32/win32/x86_64/plugins/com.sun.jna_*/com/sun/jna/{aix,darwin,freebsd,linux,openbsd,sunos}* | |
# generate linux x86_64 archive | |
( | |
cd org.haxe4e.studio/linux/gtk/x86_64; | |
tar -cf ../../../../org.haxe4e.studio-linux.gtk.x86_64.tar --exclude='HaxeStudio' --exclude='plugins/org.eclipse.justj.*/jre/bin' *; | |
tar --mode='+x' --append -f ../../../../org.haxe4e.studio-linux.gtk.x86_64.tar HaxeStudio plugins/org.eclipse.justj.*/jre/bin/* | |
) | |
gzip -9 org.haxe4e.studio-linux.gtk.x86_64.tar | |
# generate macos aarch64 archive | |
( | |
cd org.haxe4e.studio/macosx/cocoa/aarch64; | |
tar -cf ../../../../org.haxe4e.studio-macosx.cocoa.aarch64.tar --exclude='Eclipse.app/Contents/MacOS/HaxeStudio' --exclude='Eclipse.app/Contents/Eclipse/plugins/org.eclipse.justj.*/jre/bin' *; | |
tar --mode='+x' --append -f ../../../../org.haxe4e.studio-macosx.cocoa.aarch64.tar Eclipse.app/Contents/MacOS/HaxeStudio Eclipse.app/Contents/Eclipse/plugins/org.eclipse.justj.*/jre/bin/* | |
) | |
gzip -9 org.haxe4e.studio-macosx.cocoa.aarch64.tar | |
# generate macos x86_64 archive | |
( | |
cd org.haxe4e.studio/macosx/cocoa/x86_64; | |
tar -cf ../../../../org.haxe4e.studio-macosx.cocoa.x86_64.tar --exclude='Eclipse.app/Contents/MacOS/HaxeStudio' --exclude='Eclipse.app/Contents/Eclipse/plugins/org.eclipse.justj.*/jre/bin' *; | |
tar --mode='+x' --append -f ../../../../org.haxe4e.studio-macosx.cocoa.x86_64.tar Eclipse.app/Contents/MacOS/HaxeStudio Eclipse.app/Contents/Eclipse/plugins/org.eclipse.justj.*/jre/bin/* | |
) | |
gzip -9 org.haxe4e.studio-macosx.cocoa.x86_64.tar | |
# generate windows x86_64 archive | |
7z a -mx9 -tzip org.haxe4e.studio-win.x86_64.zip ./org.haxe4e.studio/win32/win32/x86_64/* | |
- name: Generate PortableApps archive | |
run: | | |
bash product/build-paf.sh | |
- name: "Determine release name" | |
id: release | |
if: ${{ !env.ACT }} | |
run: | | |
case "$GITHUB_REF_NAME" in | |
main) | |
echo "name=preview" >>"$GITHUB_OUTPUT" | |
echo "updatesite_branch=updatesite-preview" >>"$GITHUB_OUTPUT" | |
;; | |
release) | |
echo "name=stable" >>"$GITHUB_OUTPUT" | |
echo "updatesite_branch=updatesite" >>"$GITHUB_OUTPUT" | |
;; | |
esac | |
- name: "Delete previous '${{ steps.release.outputs.name }}' release" | |
if: ${{ steps.release.outputs.name != '' }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
RELEASE_NAME: ${{ steps.release.outputs.name }} | |
# https://cli.github.com/manual/gh_release_delete | |
run: | | |
GH_DEBUG=1 gh release delete "$RELEASE_NAME" --yes --cleanup-tag || true | |
- name: "Create '${{ steps.release.outputs.name }}' release" | |
if: ${{ steps.release.outputs.name != '' }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
RELEASE_NAME: ${{ steps.release.outputs.name }} | |
COMMIT_MSG: ${{ github.event.head_commit.message }} # https://stackoverflow.com/a/78420438/5116073 | |
# https://cli.github.com/manual/gh_release_create | |
run: | | |
GH_DEBUG=1 gh release create "$RELEASE_NAME" \ | |
--title "$RELEASE_NAME" \ | |
${{ steps.release.outputs.name == 'stable' && '--latest' || '' }} \ | |
${{ steps.release.outputs.name == 'preview' && '--prerelease' || '' }} \ | |
--notes "$COMMIT_MSG" \ | |
--target "${{ github.sha }}" \ | |
product/target/products/org.haxe4e.studio-linux.gtk.x86_64.tar.gz \ | |
product/target/products/org.haxe4e.studio-macosx.cocoa.aarch64.tar.gz \ | |
product/target/products/org.haxe4e.studio-macosx.cocoa.x86_64.tar.gz \ | |
product/target/products/org.haxe4e.studio-win.x86_64.zip \ | |
product/target/HaxeStudioPortable.paf.exe | |
- name: Deploy p2 update site | |
if: ${{ steps.release.outputs.name != '' }} | |
env: | |
BRANCH_NAME: ${{ steps.release.outputs.updatesite_branch }} | |
run: | | |
set -eux | |
last_commit_message=$(git log --pretty=format:"%s (%h)" -1) | |
cd /tmp | |
github_repo_url="https://${{ github.actor }}:${{ github.token }}@github.com/${{ github.repository }}" | |
if curl --output /dev/null --silent --head --fail "$github_repo_url/tree/$BRANCH_NAME"; then | |
git clone $github_repo_url --single-branch --branch "$BRANCH_NAME" updatesite | |
cd updatesite | |
# https://github.community/t/github-actions-bot-email-address/17204 | |
git config user.name "github-actions[bot]" | |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
git reset --hard HEAD^ | |
else | |
git clone $github_repo_url updatesite | |
cd updatesite | |
git checkout --orphan "$BRANCH_NAME" | |
git rm -rf . | |
cat <<EOF > index.html | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>${{ github.repository }} - Update Site</title> | |
</head> | |
<body> | |
<h1>${{ github.repository }} - Update Site</h1> | |
</body> | |
</html> | |
EOF | |
git add index.html | |
# https://github.community/t/github-actions-bot-email-address/17204 | |
git config user.name "github-actions[bot]" | |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
git commit -am "Initialize Update Site" | |
fi | |
mv $(cygpath $GITHUB_WORKSPACE)/product/target/repository/* . | |
git add --all | |
git commit -am "$last_commit_message" | |
git push origin "$BRANCH_NAME" --force | |
########################################################### | |
dependabot-pr-auto-merge: | |
########################################################### | |
needs: maven-build | |
if: ${{ github.event_name == 'pull_request' && github.actor == 'dependabot[bot]' }} | |
runs-on: ubuntu-latest | |
concurrency: dependabot-pr-auto-merge | |
permissions: | |
contents: write | |
pull-requests: write | |
steps: | |
- name: Dependabot metadata | |
id: metadata | |
uses: dependabot/fetch-metadata@v2 # https://github.com/dependabot/fetch-metadata/ | |
with: | |
github-token: "${{ secrets.GITHUB_TOKEN }}" | |
- name: Enable auto-merge for Dependabot PRs | |
if: | | |
${{ | |
( | |
steps.dependabot-metadata.outputs.package-ecosystem == 'github-actions' && | |
steps.metadata.outputs.update-type == 'version-update:semver-major' | |
) || ( | |
steps.dependabot-metadata.outputs.package-ecosystem == 'maven' && | |
steps.metadata.outputs.update-type == 'version-update:semver-minor' | |
) | |
}} | |
run: | | |
gh pr merge --auto --rebase "$PR_URL" | |
env: | |
PR_URL: ${{github.event.pull_request.html_url}} | |
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} |