Skip to content

Commit

Permalink
Fetch latest "stable" build from update check endpoint
Browse files Browse the repository at this point in the history
Also support new "binary" value for packages ref to automatically use
the same build tag as for the binary.
  • Loading branch information
FichteFoll committed Jan 12, 2025
1 parent 2310304 commit 024ea94
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 35 deletions.
26 changes: 13 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,32 @@ name: Tests
on: [push, pull_request]

jobs:
no_defpkg:
name: Without default packages
no_defpkg_stable:
name: Without default packages, latest stable
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./
with:
build: 4189
build: stable
package_root: test/no_defpkg

# TODO indentation tests
# TODO reference & definition tests

defpkg:
defpkg_stable:
name: With default packages, latest stable
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./
with:
build: 4189
default_packages: master
build: stable
default_packages: binary
package_root: test/defpkg

no_defpkg_old_build:
name: Without default packages, old build
name: Without default packages, build 4073
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -47,8 +47,8 @@ jobs:
build: latest
package_root: test/no_defpkg

third-party:
name: Third-party
third-party_stable:
name: Third-party, latest stable
runs-on: ubuntu-latest
steps:
- name: Checkout repo (primary package)
Expand All @@ -61,19 +61,19 @@ jobs:
path: third-party/INI
- uses: ./
with:
build: 4189 # stable
build: stable
package_root: test/third-party
additional_packages: third-party/INI

dummy_syntax:
name: Dummy Syntax
dummy_syntax_stable:
name: Dummy Syntax, latest stable
runs-on: ubuntu-latest
steps:
- name: Checkout repo (primary package)
uses: actions/checkout@v4
- uses: ./
with:
build: 4189 # stable
build: stable
package_root: test/dummy-syntax
dummy_syntaxes: text.dummy

Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ jobs:
include:
- build: latest # This is the default
# packages: master # If you depend on a default syntax definition
- build: stable # Fetches the binary for the latest stable build
# packages: binary # Use respective tag for the selected binary build.
- build: 3210 # Latest known ST3 build with a test binary
# packages: v3189 # Latest ST3 tag on the Packages repo
# packages: v3189 # Latest ST3 tag on the Packages repo
steps:
- uses: actions/checkout@v4
- uses: SublimeText/syntax-test-action@v2
Expand Down Expand Up @@ -136,8 +138,8 @@ jobs:

| Name | Default | Description |
| :----------------------- | :-------------- | :---------- |
| **build** | `"latest"` | ST build that should be installed as an integer. Not all builds are available. |
| **default\_packages** | `false` | Install the [default packages][] and which version (accepts any git ref, e.g. `"master"`). |
| **build** | `"latest"` | ST build that should be installed as an integer. `"latest"` is for the dev channel, `"stable"` for the stable channel. Not all builds are available. |
| **default\_packages** | `"false"` | Install the [default packages][] and which version. Accepts any git ref, e.g. `"master"`, or `"binary"` for the tag of the respective binary. Note that the corresponding tag may not always exist. |
| **default\_tests** | `false` | Whether to keep the tests of the default packages. |
| **additional\_packages** | `""` | Comma-separated list of paths to additionally checked out packages to install (e.g.: `LESS,third-party/Sass`). Uses the folders' base names as the package names to install as. |
| **additional\_tests** | `false` | Whether to keep the tests of the additional packages. |
Expand Down
65 changes: 46 additions & 19 deletions syntax-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,39 @@ folder="$RUNNER_WORKSPACE/syntax_tests"
packages="$folder/Data/Packages"
mkdir -p "$folder"

resolve_build() {
local stable_check_url="https://www.sublimetext.com/updates/4/stable_update_check"
local dev_check_url="https://www.sublimetext.com/updates/4/dev_update_check"
local build="$INPUT_BUILD"

if [[ $INPUT_BUILD == stable ]]; then
build="$(curl -s "$stable_check_url" | jq '.latest_version')"
echo >&2 "Latest stable build: $build"
elif [[ $INPUT_BUILD == latest ]]; then
build="$(curl -s "$dev_check_url" | jq '.latest_version')"
echo >&2 "Latest dev build: $build"
fi
echo "$build"
}

get_url() {
latest_url="https://download.sublimetext.com/latest/dev/linux/x64/syntax_tests"
template_3000="https://download.sublimetext.com/st3_syntax_tests_build_%s_x64.tar.bz2"
template_4000="https://download.sublimetext.com/st_syntax_tests_build_%s_x64.tar.bz2"
template_4079="https://download.sublimetext.com/st_syntax_tests_build_%s_x64.tar.xz"

case $INPUT_BUILD in
latest) echo "$latest_url";;
3*) printf "$template_3000\n" "$INPUT_BUILD";;
4*) if (( INPUT_BUILD < 4079 )); then
printf "$template_4000\n" "$INPUT_BUILD";
# Note: The syntax_tests binary for the latest build may not necessarily exist.
# Fetching from https://download.sublimetext.com/latest/dev/linux/x64/syntax_tests
# would be more reliable
# but makes using the same build for the default Packages tag harder.
local build="$1"
local template_3000="https://download.sublimetext.com/st3_syntax_tests_build_%s_x64.tar.bz2"
local template_4000="https://download.sublimetext.com/st_syntax_tests_build_%s_x64.tar.bz2"
local template_4079="https://download.sublimetext.com/st_syntax_tests_build_%s_x64.tar.xz"

case $build in
3*) printf "$template_3000\n" "$build";;
4*) if (( build < 4079 )); then
printf "$template_4000\n" "$build";
else
printf "$template_4079\n" "$INPUT_BUILD";
printf "$template_4079\n" "$build";
fi;;
*) echo >&2 "Invalid build reference: $INPUT_BUILD"; exit 100;;
*) echo >&2 "Invalid build reference: $build"; exit 100;;
esac
}

Expand All @@ -39,13 +57,21 @@ fetch_binary() {
}

fetch_default_packages() {
local binary_build="$1"
local ref="$INPUT_DEFAULT_PACKAGES"
if [[ $INPUT_DEFAULT_PACKAGES == false ]]; then
echo '::debug::Skipping default packages'
return
fi
echo "::group::Fetching default packages (ref: $INPUT_DEFAULT_PACKAGES, tests: $INPUT_DEFAULT_TESTS)"
if [[ $INPUT_DEFAULT_PACKAGES == binary ]]; then
echo "::debug::Using tag of binary version: $binary_build"
# Note: Tag may not always exist yet as they seem to be created manually.
ref="v$binary_build"
fi

echo "::group::Fetching default packages (ref: $ref, tests: $INPUT_DEFAULT_TESTS)"
pushd "$(mktemp -d)"
wget --content-disposition "https://github.com/sublimehq/Packages/archive/$INPUT_DEFAULT_PACKAGES.tar.gz"
wget --content-disposition "https://github.com/sublimehq/Packages/archive/$ref.tar.gz"
tar xf Packages-*.tar.gz
if [[ $INPUT_DEFAULT_TESTS != true ]]; then
find Packages-*/ -type f -name 'syntax_test*' -exec rm -v '{}' \;
Expand Down Expand Up @@ -101,13 +127,14 @@ SYNTAX
done
}

# TODO cache $folder/syntax_test based on $INPUT_BUILD != latest
echo "::group::Fetching binary (build $INPUT_BUILD)"
get_url | fetch_binary
# TODO cache $folder/syntax_test if not latest or stable
build="$(resolve_build)"
echo "::group::Fetching binary (build $build)"
get_url "$build" | fetch_binary
echo '::endgroup::'

# TODO cache $packages based on $INPUT_DEFAULT_PACKAGES not in (master, st3) (or resolve ref to hash)
fetch_default_packages
# TODO cache $packages based on $INPUT_DEFAULT_PACKAGES not in (master, st3, binary) (or resolve ref to hash)
fetch_default_packages "$build"

link_package

Expand Down

0 comments on commit 024ea94

Please sign in to comment.