diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..28988a2 --- /dev/null +++ b/action.yml @@ -0,0 +1,106 @@ +name: 'gitdeps action' +description: 'gitdeps' +inputs: + gitdeps_ver: + description: 'set gitdeps version' + required: false + default: '0.2.2' + gitdeps_args: + description: 'add gitdeps arguments' + required: false + default: '' +runs: + using: 'composite' + steps: + - name: get sys info (Linux) + shell: bash + if: runner.os == 'Linux' + run: | + set -e + VERSION="${{ inputs.gitdeps_ver }}" + OS_ARCH=$(uname -m | sed 's/aarch64/arm64/' | sed 's/x86_64/amd64/') + BASE_NAME="gitdeps_${VERSION}_linux_${OS_ARCH}" + FILE_NAME="${BASE_NAME}.tar.gz" + RELEASES_URL="https://github.com/Nelonn/gitdeps/releases/download" + echo "VERSION=$VERSION" >> $GITHUB_ENV + echo "OS_ARCH=$OS_ARCH" >> $GITHUB_ENV + echo "BASE_NAME=$BASE_NAME" >> $GITHUB_ENV + echo "FILE_NAME=$FILE_NAME" >> $GITHUB_ENV + echo "RELEASES_URL=$RELEASES_URL" >> $GITHUB_ENV + + - name: get sys info (macOS) + shell: bash + if: runner.os == 'macOS' + run: | + set -e + VERSION="${{ inputs.gitdeps_ver }}" + OS_ARCH=$(uname -m | sed 's/aarch64/arm64/' | sed 's/x86_64/amd64/') + BASE_NAME="gitdeps_${VERSION}_darwin_${OS_ARCH}" + FILE_NAME="${BASE_NAME}.zip" + RELEASES_URL="https://github.com/Nelonn/gitdeps/releases/download" + echo "VERSION=$VERSION" >> $GITHUB_ENV + echo "OS_ARCH=$OS_ARCH" >> $GITHUB_ENV + echo "BASE_NAME=$BASE_NAME" >> $GITHUB_ENV + echo "FILE_NAME=$FILE_NAME" >> $GITHUB_ENV + echo "RELEASES_URL=$RELEASES_URL" >> $GITHUB_ENV + + - name: get sys info (Windows) + shell: pwsh + if: runner.os == 'Windows' + run: | + $VERSION = "${{ inputs.gitdeps_ver }}" + $arch = (Get-WmiObject Win32_Processor).Architecture + if ($arch -eq 12) { + $url = "https://github.com/Nelonn/gitdeps/releases/download/v${VERSION}/gitdeps_${VERSION}_windows_arm64.zip" + } elseif ($arch -eq 9) { + $url = "https://github.com/Nelonn/gitdeps/releases/download/v${VERSION}/gitdeps_${VERSION}_windows_amd64.zip" + } elseif ($arch -eq 0) { + $url = "https://github.com/Nelonn/gitdeps/releases/download/v${VERSION}/gitdeps_${VERSION}_windows_386.zip" + } else { + Write-Error "Unsupported architecture: $arch" + exit 1 + } + echo "GITDEPS_URL=$url" >> $env:GITHUB_ENV + + - name: download archive (Unix) + shell: bash + if: runner.os != 'Windows' + run: | + echo "Downloading ${RELEASES_URL}/v${VERSION}/${FILE_NAME}" + curl --create-dirs -LO --output-dir .gitdeps "${RELEASES_URL}/v${VERSION}/${FILE_NAME}" + + - name: download archive (Windows) + shell: pwsh + if: runner.os == 'Windows' + run: | + $outputPath = ".gitdeps\gitdeps.zip" + New-Item -ItemType Directory -Force -Path ".gitdeps" | Out-Null + Invoke-WebRequest -Uri $env:GITDEPS_URL -OutFile $outputPath + echo "GITDEPS_ZIP=$outputPath" >> $env:GITHUB_ENV + + - name: extract archive (Linux) + shell: bash + if: runner.os == 'Linux' + run: tar -xf ".gitdeps/${FILE_NAME}" -C .gitdeps + + - name: extract archive (macOS) + shell: bash + if: runner.os == 'macOS' + run: unzip ".gitdeps/${FILE_NAME}" -d .gitdeps + + - name: extract archive (Windows) + shell: pwsh + if: runner.os == 'Windows' + run: | + Expand-Archive -Path $env:GITDEPS_ZIP -DestinationPath ".gitdeps" -Force + Remove-Item $env:GITDEPS_ZIP + + - name: run gitdeps (Unix) + shell: bash + if: runner.os != 'Windows' + run: .gitdeps/${BASE_NAME}/gitdeps ${{ inputs.gitdeps_args }} + + - name: run gitdeps (Windows) + shell: pwsh + if: runner.os == 'Windows' + run: .\.gitdeps\gitdeps.exe ${{ inputs.gitdeps_args }} \ No newline at end of file