diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6aec947 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM mcr.microsoft.com/azure-cli + +LABEL "com.github.actions.name"="azure-fileshare-upload" +LABEL "com.github.actions.description"="Uploads folders to Azure File Share" +LABEL "com.github.actions.icon"="arrow-up" +LABEL "com.github.actions.color"="green" +LABEL "repository"="https://github.com/cahaseler/azure-fileshare-upload" +LABEL "homepage"="https://github.com/cahaseler/azure-fileshare-upload" +LABEL "maintainer"="Craig Haseler " + +ADD entrypoint.sh /entrypoint.sh +RUN chmod +x entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..86d71f5 --- /dev/null +++ b/README.md @@ -0,0 +1,28 @@ +# GitHub Action to Upload Directories to Azure FileShare + +This action uses the [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli) to upload a directory of your choice to your Azure File Storage. + +## Usage + +### Example + +Place in a `.yml` file in your `.github/workflows` folder. + +```yaml +name: Upload To Azure FileShare +on: + push: + branches: + - master +jobs: + upload: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: cahaseler/azure-fileshare-upload@v1.0.0 + with: + account_name: storageaccount + account_key: ${{secrets.ACCOUNT_KEY}} + share_name: azure-fileshare + source_dir: config +``` diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..b2426e8 --- /dev/null +++ b/action.yml @@ -0,0 +1,22 @@ +name: "Azure File Share Upload" +author: "Craig Haseler " +description: "Uploads folders to Azure File Share" +branding: + icon: "arrow-up" + color: "green" +inputs: + account_name: + description: "The storage account name" + required: true + account_key: + description: "The storage account key. Make sure to treat this as a secret" + required: true + share_name: + description: "The name of the fileshare you are uploading to" + required: true + source_dir: + description: "The name of the directory in your Github you want to replace the contents of the fileshare with. Defaults to the whole repository." + required: false +runs: + using: "docker" + image: "Dockerfile" diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..9fdeb24 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +set -e + +if [ -z "$INPUT_ACCOUNT_NAME" ]; then + echo "Sccount name is not set. Quitting." + exit 1 +fi + +if [ -z "$INPUT_ACCOUNT_KEY" ]; then + echo "Sccount name is not set. Quitting." + exit 1 +fi + +if [ -z "$INPUT_SHARE_NAME" ]; then + echo "Share name is not set. Quitting." + exit 1 +fi + + +$FILES=/ +if [ -z "$INPUT_SOURCE_DIR" ]; then + echo "Source name is not set. Running on entire repo." + $FILES=$INPUT_SOURCE_DIR +fi + +for f in $FILES +do + echo "Uploading $f..." + az storage file upload \ + --account-name $INPUT_ACCOUNT_NAME + --account-key $INPUT_ACCOUNT_KEY + --destination $INPUT_SHARE_NAME + --source $FILES +done \ No newline at end of file