From bd5c7dcbd9c9714ab50c3ef0e69a8de3af9f2fc3 Mon Sep 17 00:00:00 2001 From: Florian Loitsch Date: Fri, 26 Jan 2024 11:52:30 +0400 Subject: [PATCH 1/2] Add CI and fix version. --- .github/workflows/ci.yml | 89 ++++++++++++++++++++++++++++++++++++++++ action.yml | 3 +- 2 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..5bf6aa0 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,89 @@ +name: CI + +on: + push: + branches: + - "*" + - "*/*" + +jobs: + build: + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + version: [v2.0.0-alpha.130, latest, ""] + + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup with version argument + id: setup1 + if: ${{ matrix.version != '' }} + uses: ./ + with: + toit-version: v2.0.0-alpha.130 + + - name: Setup without version argument + id: setup2 + if: ${{ matrix.version == '' }} + uses: ./ + + - name: Test Toit in Path + shell: bash + run: | + toit.run --version + toit.pkg --version + + - name: Test Toit in Path - native shell + run: | + toit.run --version + toit.pkg --version + + - name: Test outputs + shell: bash + run: | + if [[ -z "${{ matrix.version }}" ]]; then + echo "No version argument" + TOIT_URL="${{ steps.setup2.outputs.toit-url }}" + TOIT_DIR="${{ steps.setup2.outputs.toit-install-dir }}" + TOIT_SDK="${{ steps.setup2.outputs.toit-sdk-path }}" + TOIT_VERSION="${{ steps.setup2.outputs.toit-version }}" + else + echo "With version argument" + TOIT_URL="${{ steps.setup1.outputs.toit-url }}" + TOIT_DIR="${{ steps.setup1.outputs.toit-install-dir }}" + TOIT_SDK="${{ steps.setup1.outputs.toit-sdk-path }}" + TOIT_VERSION="${{ steps.setup1.outputs.toit-version }}" + fi + if [[ "$TOIT_VERSION" == "" ]]; then + echo "No version" + exit 1 + fi + + if [[ "${{ matrix.version }}" != "latest" && "${{ matrix.version }}" != "" ]]; then + if [[ "$TOIT_VERSION" != "${{ matrix.version }}" ]]; then + echo "Version does not match" + exit 1 + fi + fi + + # The install-dir should have a toit directory. + if [[ ! -d "$TOIT_DIR/toit" ]]; then + echo "Install dir does not exist" + exit 1 + fi + + # The SDK-path is the toit directory. + if [[ "$TOIT_SDK" != "$TOIT_DIR/toit" ]]; then + echo "SDK path does not match install dir" + exit 1 + fi + + # The URL should be a valid URL. + if [[ ! "$TOIT_URL" =~ ^https://.* ]]; then + echo "URL is not a valid URL" + exit 1 + fi diff --git a/action.yml b/action.yml index 1400ca6..23fee21 100644 --- a/action.yml +++ b/action.yml @@ -103,4 +103,5 @@ runs: shell: bash run: | cd '${{ steps.tmp-dir.outputs.TOIT_INSTALL_DIR }}' - echo "TOIT_VERSION=$(cat toit/VERSION)" >> $GITHUB_OUTPUT + # We use 'sed' as some version files had a trailing space. + echo "TOIT_VERSION=$(sed 's/ $//' toit/VERSION)" >> $GITHUB_OUTPUT From 8c0afa42b91736a1a409277141a2f00b471d4efd Mon Sep 17 00:00:00 2001 From: Florian Loitsch Date: Fri, 26 Jan 2024 11:53:02 +0400 Subject: [PATCH 2/2] Use curl to download. --- action.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/action.yml b/action.yml index 23fee21..1f57767 100644 --- a/action.yml +++ b/action.yml @@ -42,6 +42,8 @@ runs: echo "UNSUPPORTED RUNNER: $RUNNER_OS" exit 1 fi + echo "TOIT_FILE=$TOIT_FILE" >> $GITHUB_OUTPUT + if [[ $TOIT_VERSION = latest ]]; then echo "TOIT_URL=https://github.com/toitlang/toit/releases/latest/download/$TOIT_FILE" >> $GITHUB_OUTPUT else @@ -72,10 +74,11 @@ runs: echo TOIT_INSTALL_DIR=$TOIT_INSTALL_DIR >> $GITHUB_OUTPUT - name: Download Toit - uses: suisei-cn/actions-download-file@v1.3.0 - with: - url: ${{ steps.setup_constants.outputs.TOIT_URL }} - target: ${{ steps.tmp-dir.outputs.TOIT_INSTALL_DIR }} + shell: bash + run: | + cd '${{ steps.tmp-dir.outputs.TOIT_INSTALL_DIR }}' + # Downloads the tar.gz file. + curl -L -o ${{ steps.setup_constants.outputs.TOIT_FILE }} ${{ steps.setup_constants.outputs.TOIT_URL }} - name: Extract Toit shell: bash