Skip to content

Commit

Permalink
Enable building with Gradle via GitHub Actions (#10)
Browse files Browse the repository at this point in the history
Running unit tests on `win32-x86` is currently disabled (`libstdc++` is not in `PATH`).
  • Loading branch information
0x6675636b796f75676974687562 authored Mar 30, 2023
1 parent ac91003 commit ae7bef3
Show file tree
Hide file tree
Showing 11 changed files with 423 additions and 92 deletions.
17 changes: 17 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "gradle"
# Files stored in repository root
directory: "/"
schedule:
interval: "weekly"

- package-ecosystem: "github-actions"
# Workflow files stored in the
# default location of `.github/workflows`
directory: "/"
schedule:
interval: "weekly"
140 changes: 131 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
push:
branches:
- 'master'
tags:
- 'v*'
workflow_dispatch:

env:
Expand Down Expand Up @@ -151,7 +153,7 @@ jobs:
retention-days: 1

test:
name: 'Run tests (${{ matrix.jna-os }}-${{ matrix.jna-arch }})'
name: 'Run unit tests (${{ matrix.jna-os }}-${{ matrix.jna-arch }})'
runs-on: ${{ matrix.os }}
needs: build-native

Expand All @@ -174,6 +176,21 @@ jobs:
exclude:
- jna-os: darwin
jna-arch: x86
# `tree-sitter-cpp.dll` depends on `libstdc++` and `libgcc_s`.
# Any attempts to load it fail with an `UnsatisfiedLinkError`
# whenever `mingw{32,64}\bin` is not in `PATH`.
#
# Until we start linking against `libstdc++` statically,
# disable tests on `win32-x86`.
- jna-os: win32
jna-arch: x86

# A possible workaround for <https://github.com/dorny/test-reporter/issues/168>.
permissions:
checks: write
contents: write
pull-requests: write
statuses: write

steps:
- uses: actions/checkout@v3
Expand All @@ -184,23 +201,63 @@ jobs:
# https://github.com/actions/checkout/issues/206#issuecomment-607496604.
fetch-depth: 0

- uses: actions/setup-java@v3
- name: 'Download native libraries'
uses: actions/download-artifact@v3
with:
name: 'libtree-sitter-${{ matrix.jna-os }}-${{ matrix.jna-arch }}'
path: jna-lib/src/main/resources/${{ matrix.jna-os }}-${{ matrix.jna-arch }}/

- name: 'Strip version information from file names'
if: ${{ runner.os != 'Windows' }}
run: |
for file in $(find jna-lib/src/main/resources/${{ matrix.jna-os }}-${{ matrix.jna-arch }}/ -type f \( -name 'lib*.so*' -o -name 'lib*.dylib' \))
do
old_file="$(basename "${file}")"
new_file="$(echo "${old_file}" | sed -n '/^lib..*\.[0-9]..*/s/\.[0-9][0-9]*//gp')"
if [[ "${old_file}" != "${new_file}" ]]
then
echo "mv ${file} $(dirname ${file})/${new_file}"
mv -v "${file}" "$(dirname "${file}")/${new_file}"
fi
done
shell: bash

- name: 'Set POSIX attributes'
if: ${{ runner.os != 'Windows' }}
run: |
find jna-lib/src/main/resources/${{ matrix.jna-os }}-${{ matrix.jna-arch }}/ -type f \( -name 'lib*.so' -o -name 'lib*.dylib' \) -exec chmod 755 '{}' ';'
find jna-lib/src/main/resources/${{ matrix.jna-os }}-${{ matrix.jna-arch }}/ -type f \( -name 'lib*.so' -o -name 'lib*.dylib' \) -exec ls -lF --color=always '{}' ';'
shell: bash

- name: 'Set up Java 11'
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 11
java-package: 'jdk+fx'
architecture: ${{ matrix.arch }}

- name: 'Build sample source code'
run: |
java -version
shell: bash
- name: 'Run unit tests'
id: test
uses: gradle/gradle-build-action@v2
with:
gradle-version: wrapper
arguments: |
--continue
build
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

build:
name: 'Build Kotlin code'
publish:
name: 'Publish packages'
if: ${{ github.event_name == 'push' && github.ref_type == 'tag' }}
runs-on: ubuntu-latest
needs: build-native

permissions:
# Explicitly granted, necessary for the `publish` step.
packages: write

steps:
- uses: actions/checkout@v3
with:
Expand All @@ -210,12 +267,77 @@ jobs:
# https://github.com/actions/checkout/issues/206#issuecomment-607496604.
fetch-depth: 0

- uses: actions/setup-java@v3
- name: 'Download native libraries (darwin-x86-64)'
uses: actions/download-artifact@v3
with:
name: 'libtree-sitter-darwin-x86-64'
path: jna-lib/src/main/resources/darwin-x86-64/

- name: 'Download native libraries (linux-x86)'
uses: actions/download-artifact@v3
with:
name: 'libtree-sitter-linux-x86'
path: jna-lib/src/main/resources/linux-x86/

- name: 'Download native libraries (linux-x86-64)'
uses: actions/download-artifact@v3
with:
name: 'libtree-sitter-linux-x86-64'
path: jna-lib/src/main/resources/linux-x86-64/

- name: 'Download native libraries (win32-x86)'
uses: actions/download-artifact@v3
with:
name: 'libtree-sitter-win32-x86'
path: jna-lib/src/main/resources/win32-x86/

- name: 'Download native libraries (win32-x86-64)'
uses: actions/download-artifact@v3
with:
name: 'libtree-sitter-win32-x86-64'
path: jna-lib/src/main/resources/win32-x86-64/

- name: 'Strip version information from file names'
if: ${{ runner.os != 'Windows' }}
run: |
for file in $(find jna-lib/src/main/resources/ -type f \( -name 'lib*.so*' -o -name 'lib*.dylib' \))
do
old_file="$(basename "${file}")"
new_file="$(echo "${old_file}" | sed -n '/^lib..*\.[0-9]..*/s/\.[0-9][0-9]*//gp')"
if [[ "${old_file}" != "${new_file}" ]]
then
echo "mv ${file} $(dirname ${file})/${new_file}"
mv -v "${file}" "$(dirname "${file}")/${new_file}"
fi
done
shell: bash

- name: 'Set POSIX attributes'
if: ${{ runner.os != 'Windows' }}
run: |
find jna-lib/src/main/resources/ -type f \( -name 'lib*.so' -o -name 'lib*.dylib' \) -exec chmod 755 '{}' ';'
find jna-lib/src/main/resources/ -type f \( -name 'lib*.so' -o -name 'lib*.dylib' \) -exec ls -lF --color=always '{}' ';'
shell: bash

- name: 'Set up Java 11'
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 11
java-package: 'jdk+fx'

- name: 'Publish a release'
id: publish
uses: gradle/gradle-build-action@v2
with:
gradle-version: wrapper
arguments: |
-x test
build
publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

report:
name: 'Publish JUnit test results (${{ matrix.jna-os }}-${{ matrix.jna-arch }})'
if: ${{ always() }}
Expand Down
52 changes: 52 additions & 0 deletions .github/workflows/dependencies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: 'Dependencies'

on:
push:
branches:
- 'master'

env:
GRADLE_OPTS: -Dorg.gradle.daemon=true -Dorg.gradle.parallel=true -Dorg.gradle.welcome=never

jobs:
dependencies:
name: 'Dependencies'
runs-on: ubuntu-latest

# The Dependency Submission API requires write permission.
permissions:
contents: write

steps:
- uses: actions/checkout@v3
with:
# Fetch Git tags, so that semantic version can be calculated.
# Alternatively, run `git fetch --prune --unshallow --tags` as the
# next step, see
# https://github.com/actions/checkout/issues/206#issuecomment-607496604.
fetch-depth: 0

- name: 'Set up Java 11'
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 11
java-package: 'jdk+fx'

- name: 'Set up Gradle'
id: build
uses: gradle/gradle-build-action@v2
with:
gradle-version: wrapper

# `gradlew :jna-lib:dependencies --configuration compileClasspath`
- name: 'Run snapshot action'
uses: mikepenz/[email protected]
with:
use-gradlew: true
gradle-build-module: |-
:jna-lib
# `compileClasspath` configuration has no dependencies in multiplatform
# projects.
gradle-build-configuration: |-
compileClasspath
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ bin

pkgconfig
include

/jna-lib/src/main/resources/win32-x86/tree-sitter-cpp.dll
/jna-lib/src/main/resources/win32-x86-64/tree-sitter-cpp.dll
Loading

0 comments on commit ae7bef3

Please sign in to comment.