From 25694362f010cc7b1edec27d8c6c17c48649ec3e Mon Sep 17 00:00:00 2001 From: Scion Date: Wed, 22 Mar 2023 02:09:29 -0700 Subject: [PATCH] initial commit --- distros/busybox/Dockerfile | 7 +++ distros/busybox/action.yaml | 14 ++++++ distros/busybox/entrypoint.sh | 15 ++++++ distros/rockylinux2/Dockerfile | 18 ++++++++ distros/rockylinux2/action.yaml | 19 ++++++++ distros/rockylinux2/entrypoint.sh | 18 ++++++++ distros/rockylinux2/setup_gpg.sh | 29 ++++++++++++ docker/docker-cp/action.yaml | 76 +++++++++++++++++++++++++++++++ dotnet/Dockerfile | 9 ++++ dotnet/action.yaml | 11 +++++ dotnet/startup.sh | 2 + utils/chown/action.yaml | 38 ++++++++++++++++ utils/compress/action.yaml | 67 +++++++++++++++++++++++++++ utils/download/action.yaml | 30 ++++++++++++ utils/download/download.sh | 8 ++++ utils/extract/action.yaml | 45 ++++++++++++++++++ 16 files changed, 406 insertions(+) create mode 100644 distros/busybox/Dockerfile create mode 100644 distros/busybox/action.yaml create mode 100644 distros/busybox/entrypoint.sh create mode 100644 distros/rockylinux2/Dockerfile create mode 100644 distros/rockylinux2/action.yaml create mode 100644 distros/rockylinux2/entrypoint.sh create mode 100644 distros/rockylinux2/setup_gpg.sh create mode 100644 docker/docker-cp/action.yaml create mode 100644 dotnet/Dockerfile create mode 100644 dotnet/action.yaml create mode 100644 dotnet/startup.sh create mode 100644 utils/chown/action.yaml create mode 100644 utils/compress/action.yaml create mode 100644 utils/download/action.yaml create mode 100644 utils/download/download.sh create mode 100644 utils/extract/action.yaml diff --git a/distros/busybox/Dockerfile b/distros/busybox/Dockerfile new file mode 100644 index 0000000..a5caa7a --- /dev/null +++ b/distros/busybox/Dockerfile @@ -0,0 +1,7 @@ +# Container image that runs your code +FROM busybox:1.36.0 + +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/distros/busybox/action.yaml b/distros/busybox/action.yaml new file mode 100644 index 0000000..a0f0161 --- /dev/null +++ b/distros/busybox/action.yaml @@ -0,0 +1,14 @@ +name: busybox +description: "Run busybox commands." +inputs: + args: + description: "Shell arguments to pass into busybox." + required: true +outputs: + console: + description: "The console output of the command." +runs: + using: docker + image: Dockerfile + args: + - ${{ inputs.args }} \ No newline at end of file diff --git a/distros/busybox/entrypoint.sh b/distros/busybox/entrypoint.sh new file mode 100644 index 0000000..f8ae402 --- /dev/null +++ b/distros/busybox/entrypoint.sh @@ -0,0 +1,15 @@ +#!/bin/sh +ARGS="$@" + +OUTPUT=$(sh -c "$ARGS") +RESULT=$? +echo "$OUTPUT" + +#Output multiline strings. +#https://trstringer.com/github-actions-multiline-strings/ +OUTPUT="${OUTPUT//'%'/'%25'}" +OUTPUT="${OUTPUT//$'\n'/'%0A'}" +OUTPUT="${OUTPUT//$'\r'/'%0D'}" +echo "::set-output name=console::$OUTPUT" + +exit $RESULT \ No newline at end of file diff --git a/distros/rockylinux2/Dockerfile b/distros/rockylinux2/Dockerfile new file mode 100644 index 0000000..46e88cf --- /dev/null +++ b/distros/rockylinux2/Dockerfile @@ -0,0 +1,18 @@ +# Container image that runs your code +FROM rockylinux:9.1 + +RUN dnf install -y \ + rpm-sign \ + unzip \ + pinentry \ + wget \ + zip + +COPY setup_gpg.sh /setup_gpg.sh +RUN chmod +x /setup_gpg.sh +RUN /setup_gpg.sh + +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/distros/rockylinux2/action.yaml b/distros/rockylinux2/action.yaml new file mode 100644 index 0000000..49c2451 --- /dev/null +++ b/distros/rockylinux2/action.yaml @@ -0,0 +1,19 @@ +name: rockylinux +description: "Run rockylinux commands." +inputs: + #args: + # description: "Shell arguments to pass into Rocky Linux." + # required: true + workingDir: + description: "Working directory to execute the commands in." + required: true + default: "." +outputs: + console: + description: "The console output of the command." +runs: + using: docker + image: Dockerfile + args: + #- "${{ inputs.workingDir }}" + - "${{ inputs.args }}" \ No newline at end of file diff --git a/distros/rockylinux2/entrypoint.sh b/distros/rockylinux2/entrypoint.sh new file mode 100644 index 0000000..1b4f23e --- /dev/null +++ b/distros/rockylinux2/entrypoint.sh @@ -0,0 +1,18 @@ +#!/bin/sh +WORKDIR="$1" +cd "$WORKDIR" + +ARGS_ARRAY=($@) +ARGS=${array[@]:1} +OUTPUT=$(bash -c "$ARGS") +RESULT=$? +echo "$OUTPUT" + +#Output multiline strings. +#https://trstringer.com/github-actions-multiline-strings/ +OUTPUT="${OUTPUT//'%'/'%25'}" +OUTPUT="${OUTPUT//$'\n'/'%0A'}" +OUTPUT="${OUTPUT//$'\r'/'%0D'}" +echo "::set-output name=console::$OUTPUT" + +exit $RESULT \ No newline at end of file diff --git a/distros/rockylinux2/setup_gpg.sh b/distros/rockylinux2/setup_gpg.sh new file mode 100644 index 0000000..1c6c3af --- /dev/null +++ b/distros/rockylinux2/setup_gpg.sh @@ -0,0 +1,29 @@ +#!/bin/bash +#Importing gpg key via cli +#https://d.sb/2016/11/gpg-inappropriate-ioctl-for-device-errors +GPG_CONF="$HOME/.gnupg/gpg.conf" +GPG_AGENT_CONF="$HOME/.gnupg/gpg-agent.conf" + +function create_file +{ + FILE_PATH="$1" + CONTENTS="$2" + DIR=$(dirname "$FILE_PATH") + + mkdir -p "$DIR" + chmod 700 "$DIR" + echo "$CONTENTS" > "$FILE_PATH" +} + +create_file "$GPG_CONF" "$(cat <&1) && RESULT=$? || RESULT=$? + echo "$OUTPUT" + + echo "Removing Temporary Container" + docker stop ${{ inputs.containerName }} -t 0 + + exit $RESULT + shell: bash diff --git a/dotnet/Dockerfile b/dotnet/Dockerfile new file mode 100644 index 0000000..ed16152 --- /dev/null +++ b/dotnet/Dockerfile @@ -0,0 +1,9 @@ +FROM mcr.microsoft.com/dotnet/sdk:7.0 + +# https://github.com/dotnet-script/dotnet-script +#RUN dotnet tool install dotnet-script --tool-path /usr/bin + +COPY ./startup.sh /startup.sh +RUN chmod +x /startup.sh + +ENTRYPOINT [ "/startup.sh" ] \ No newline at end of file diff --git a/dotnet/action.yaml b/dotnet/action.yaml new file mode 100644 index 0000000..e7cc7e1 --- /dev/null +++ b/dotnet/action.yaml @@ -0,0 +1,11 @@ +name: "dotnet" +description: "Runs the specified dotnet command." +inputs: + command: + description: "The command to run." + required: false +runs: + using: docker + image: Dockerfile + args: + - ${{ inputs.command }} \ No newline at end of file diff --git a/dotnet/startup.sh b/dotnet/startup.sh new file mode 100644 index 0000000..26b8e3a --- /dev/null +++ b/dotnet/startup.sh @@ -0,0 +1,2 @@ +#!/bin/bash +dotnet $@ \ No newline at end of file diff --git a/utils/chown/action.yaml b/utils/chown/action.yaml new file mode 100644 index 0000000..0f3e907 --- /dev/null +++ b/utils/chown/action.yaml @@ -0,0 +1,38 @@ +name: chown +description: "Take or change ownership of the specified files." +inputs: + uid: + description: "User id." + required: false + default: "" + gid: + description: "Group id." + required: false + default: "" + file: + description: "File or folder to own." + required: true +runs: + using: "composite" + steps: + - name: "Determine UID and GID." + id: ids + run: | + USER_UID="${{ inputs.uid }}" + USER_GID="${{ inputs.gid }}" + if [[ -z "$USER_UID" ]]; then + USER_UID=$(id -u) + fi + if [[ -z "$USER_GID" ]]; then + USER_GID=$(id -g) + fi + + echo $USER_UID:$USER_GID + + echo "::set-output name=uid::$USER_UID" + echo "::set-output name=gid::$USER_GID" + shell: bash + - name: "Take ownership of output." + uses: act/common/distros/busybox@master + with: + args: chown ${{ steps.ids.outputs.uid }}:${{ steps.ids.outputs.gid }} "${{ inputs.file }}" -R diff --git a/utils/compress/action.yaml b/utils/compress/action.yaml new file mode 100644 index 0000000..fc9ca64 --- /dev/null +++ b/utils/compress/action.yaml @@ -0,0 +1,67 @@ +name: compress +description: "Compress a file or directory" +inputs: + files: + description: "File or directory to compress." + required: true + name: + description: "Filename of the zip file." + required: true + recursive: + description: "Recursivly zip files. Default: true" + required: false + default: "true" + quiet: + description: "Don't output every zipped file. Default: true" + required: false + default: "true" + compressionLevel: + description: "Compression level between 1-9. Default: 6" + required: false + default: "6" + compressionMethod: + description: "Compression method. Options: deflate or store. Default: deflate" + required: true + default: "deflate" + additionalArgs: + description: "Additional arguments." + required: false + workingDir: + description: "Working directory to perform the command in. Default: ." + required: true + default: "." +outputs: + publicKey: + description: "The compressed archive." + value: ${{ steps.command.outputs.name }} +runs: + using: "composite" + steps: + - name: "Build command." + id: command + run: | + cd "${{ inputs.workingDir }}" + mkdir -p "$(dirname '${{ inputs.name }}')" + COMMAND="zip -${{ inputs.compressionLevel }} -Z ${{ inputs.compressionMethod }} ${{ inputs.additionalArgs }}" + if [[ "${{ inputs.recursive }}" == "true" ]]; then + COMMAND="$COMMAND -r" + fi + if [[ "${{ inputs.quiet }}" == "true" ]]; then + COMMAND="$COMMAND -q" + fi + NAME="${{ inputs.name }}" + NAME="${NAME/ /\\ }" + FILES="${{ inputs.files }}" + FILES="${FILES/ /\\ }" + + COMMAND="$COMMAND $NAME $FILES" + echo "Compressing with: $COMMAND" + echo "::set-output name=command::$COMMAND" + echo "::set-output name=name::${{ inputs.name }}" + shell: bash + - name: "Compress archive." + id: compress + uses: act/common/distros/rockylinux@master + with: + workingDir: ${{ inputs.workingDir }} + args: ${{ steps.command.outputs.command }} diff --git a/utils/download/action.yaml b/utils/download/action.yaml new file mode 100644 index 0000000..0b68d13 --- /dev/null +++ b/utils/download/action.yaml @@ -0,0 +1,30 @@ +name: download +description: "Download a file from a URL." +inputs: + url: + description: "Url to download from." + required: true + outputFile: + description: "Output file of the download." + required: false + default: "" +outputs: + file: + description: "The path of the downloaded file." + value: ${{ steps.download.outputs.file }} +runs: + using: "composite" + steps: + - run: cp -f ${{ github.action_path }}/download.sh _download.sh + shell: bash + - name: "Download file." + id: download + uses: act/common/distros/rockylinux@master + with: + args: sh "_download.sh" "${{ inputs.url }}" "${{ inputs.outputFile }}" + - run: rm _download.sh + shell: bash + - name: "Own artifacts." + uses: act/common/utils/chown@master + with: + file: ${{ steps.download.outputs.file }} \ No newline at end of file diff --git a/utils/download/download.sh b/utils/download/download.sh new file mode 100644 index 0000000..a8faae6 --- /dev/null +++ b/utils/download/download.sh @@ -0,0 +1,8 @@ +#!/bin/sh +URL="$1" +OUTPUT_FILE="$2" +if [[ -z "$OUTPUT_FILE" ]]; then +OUTPUT_FILE="$(basename $URL)" +fi +wget $URL -O "$OUTPUT_FILE" +echo "::set-output name=file::$OUTPUT_FILE" \ No newline at end of file diff --git a/utils/extract/action.yaml b/utils/extract/action.yaml new file mode 100644 index 0000000..c8ec811 --- /dev/null +++ b/utils/extract/action.yaml @@ -0,0 +1,45 @@ +name: extract +description: "Extract a compressed file." +inputs: + file: + description: "File to extract." + required: true + outputDir: + description: "Directory to extract to." + required: false + default: "" + prefixArgs: + description: "Additional arguments to pass in early." + required: false + additionalArgs: + description: "Additional arguments to pass in." + required: false + deleteSource: + description: "Delete the compressed file afterwards." + required: false + default: "false" +runs: + using: "composite" + steps: + - name: "Build command." + id: command + run: | + COMMAND="unzip ${{ inputs.prefixArgs }} -o ${{ inputs.file }} ${{ inputs.additionalArgs }}" + OUTPUT_DIR="${{ inputs.outputDir }}" + if [[ -n "$OUTPUT_DIR" ]]; then + COMMAND="$COMMAND" -d "$OUTPUT_DIR" + fi + echo "::set-output name=command::$COMMAND" + shell: bash + - name: "Convert file." + id: convert + uses: act/common/distros/busybox@master + with: + args: ${{ steps.command.outputs.command }} + - name: "Delete source." + run: | + if [[ ${{ inputs.deleteSource }} != "true" ]]; then + return + fi + rm ${{ inputs.file }} + shell: bash \ No newline at end of file