├── .github └── workflows │ └── code-review.yml ├── Dockerfile ├── LICENSE ├── README.md ├── action.yml └── entrypoint.sh /.github/workflows/code-review.yml: -------------------------------------------------------------------------------- 1 | name: Code Review 2 | 3 | on: 4 | pull_request: 5 | types: [opened, synchronize, reopened] 6 | 7 | jobs: 8 | review: 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - name: Checkout code 13 | uses: actions/checkout@v4 14 | with: 15 | fetch-depth: 0 16 | 17 | - name: Get the PR diff 18 | uses: GrantBirki/git-diff-action@v2.6.0 19 | id: git-diff 20 | with: 21 | raw_diff_file_output: diff.txt 22 | file_output_only: "true" 23 | 24 | - name: Review code 25 | id: code-review 26 | run: | 27 | # Get the diff 28 | escaped_diff=$(cat ${{ steps.git-diff.outputs.raw-diff-path }} | jq -sRr @json | sed -e 's/^"//' -e 's/"$//') 29 | 30 | # Send to OpenAI for review 31 | response=$(curl -X POST https://api.openai.com/v1/chat/completions \ 32 | -H "Content-Type: application/json" \ 33 | -H "Authorization: Bearer ${{ secrets.OPENAI_API_KEY }}" \ 34 | -d '{ 35 | "model": "gpt-4o", 36 | "messages": [ 37 | { 38 | "role": "system", 39 | "content": "Review this pull request and suggest improvements. Check for any logical and security concerns with the code. If you do not have any recommendations, respond with \"Looks good to me!\"." 40 | }, 41 | { 42 | "role": "user", 43 | "content": "```\n'"$escaped_diff"'\n```\n" 44 | } 45 | ] 46 | }') 47 | 48 | # Extract the review 49 | comments=$(echo $response | jq -r '.choices[0].message.content' | jq -sRr @json) 50 | 51 | echo "comments=$(echo $comments)" >> $GITHUB_OUTPUT 52 | 53 | - name: Post review comments 54 | uses: actions/github-script@v7 55 | with: 56 | script: | 57 | github.rest.issues.createComment({ 58 | issue_number: context.issue.number, 59 | owner: context.repo.owner, 60 | repo: context.repo.repo, 61 | body: ${{ steps.code-review.outputs.comments }} 62 | }) 63 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mcr.microsoft.com/azure-cli 2 | 3 | LABEL "com.github.actions.name"="azure-blob-storage-upload" 4 | LABEL "com.github.actions.description"="Uploads assets to Azure Blob Storage" 5 | LABEL "com.github.actions.icon"="box" 6 | LABEL "com.github.actions.color"="green" 7 | LABEL "repository"="https://github.com/bacongobbler/azure-blob-storage-upload" 8 | LABEL "homepage"="https://github.com/bacongobbler/azure-blob-storage-upload" 9 | LABEL "maintainer"="Matthew Fisher " 10 | 11 | ADD entrypoint.sh /entrypoint.sh 12 | RUN chmod +x entrypoint.sh 13 | 14 | ENTRYPOINT ["/entrypoint.sh"] 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) Matthew Fisher 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GitHub Action to Upload Assets to Azure Blob Storage 2 | 3 | This action is designed to use the [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest) to upload a directory of your choice to your Azure Blob Storage account. 4 | 5 | ## Usage 6 | 7 | ### Example 8 | 9 | Place in a `.yml` file such as this one in your `.github/workflows` folder. [Refer to the documentation on workflow YAML syntax here.](https://help.github.com/en/articles/workflow-syntax-for-github-actions) 10 | 11 | ```yaml 12 | name: Upload To Azure Blob Storage 13 | on: 14 | push: 15 | branches: 16 | - main 17 | jobs: 18 | upload: 19 | runs-on: ubuntu-latest 20 | steps: 21 | - uses: actions/checkout@v4 22 | - uses: bacongobbler/azure-blob-storage-upload@main 23 | with: 24 | source_dir: _dist 25 | container_name: www 26 | connection_string: ${{ secrets.ConnectionString }} 27 | extra_args: '--pattern *.tar.gz' 28 | # WARNING: this will overwrite existing blobs in your blob storage 29 | overwrite: 'true' 30 | ``` 31 | 32 | If you want to synchronize local and remote state (for example, if you are publishing a static website), enable the `sync` flag. 33 | 34 | ### Required Variables 35 | 36 | | Key | Value | 37 | |---------------------|----------------------------------------------------------------------------| 38 | | `container_name` | The name of the storage account container these assets will be uploaded to | 39 | | `source_dir` | The name of the directory you want to upload | 40 | 41 | ### Optional Variables 42 | 43 | | Key | Value | 44 | |---------------------|-----------------------------------------------------------------------------------------------------------------------------------------| 45 | | `account_name` | The name of the storage account. Required if `sas_token` is used | 46 | | `connection_string` | The connection string for the storage account. Used if value is set. Either `connection_string` or `sas_token` must be supplied | 47 | | `extra_args` | Extra arguments that can be passed to `az storage blob upload-batch`. Useful for passing flags like `--pattern` or `--destination-path` | 48 | | `overwrite` | Overwrite existing files in the destination container. Defaults to false | 49 | | `sas_token` | The shared access signature token for the storage account. Either connection\_string or sas\_token must be supplied | 50 | | `sync` | Use `az storage blob sync` to synchronize blobs recursively. Defaults to false (`az storage blob upload-batch`) | 51 | 52 | ## License 53 | 54 | This project is distributed under the [Apache 2 license](LICENSE). 55 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: "Azure Blob Storage Upload" 2 | author: "Matthew Fisher " 3 | description: "Uploads assets to Azure Blob Storage" 4 | branding: 5 | icon: "box" 6 | color: "green" 7 | inputs: 8 | connection_string: 9 | description: "The connection string for the storage account. Used if value is set. Either connection_string or sas_token must be supplied" 10 | required: false 11 | sas_token: 12 | description: "The shared access signature token for the storage account. Either connection_string or sas_token must be supplied" 13 | required: false 14 | account_name: 15 | description: "The name of the storage account. Required if sas_token is used" 16 | required: false 17 | container_name: 18 | description: "The name of the storage account container these assets will be uploaded to" 19 | required: true 20 | source_dir: 21 | description: "The name of the directory you want to upload" 22 | required: true 23 | extra_args: 24 | description: "Extra arguments that can be passed to `az storage blob upload-batch|sync`. Useful for passing flags like `--pattern` or `--destination-path`" 25 | required: false 26 | sync: 27 | description: "Use `az storage blob sync` to synchronize blobs recursively" 28 | required: false 29 | overwrite: 30 | description: "Overwrite existing files in the destination container. Defaults to false" 31 | required: false 32 | runs: 33 | using: "docker" 34 | image: "Dockerfile" 35 | -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | if [[ -z "$INPUT_SOURCE_DIR" ]]; then 6 | echo "source directory is not set. Quitting." 7 | exit 1 8 | fi 9 | 10 | if [[ -z "$INPUT_CONTAINER_NAME" ]]; then 11 | echo "storage account container name is not set. Quitting." 12 | exit 1 13 | fi 14 | 15 | CONNECTION_METHOD="" 16 | 17 | if [[ -n "$INPUT_CONNECTION_STRING" ]]; then 18 | CONNECTION_METHOD="--connection-string $INPUT_CONNECTION_STRING" 19 | elif [[ -n "$INPUT_SAS_TOKEN" ]]; then 20 | if [[ -n "$INPUT_ACCOUNT_NAME" ]]; then 21 | CONNECTION_METHOD="--sas-token $INPUT_SAS_TOKEN --account-name $INPUT_ACCOUNT_NAME" 22 | else 23 | echo "account_name is required if using a sas_token. account_name is not set. Quitting." 24 | exit 1 25 | fi 26 | else 27 | echo "either connection_string or sas_token are required and neither is set. Quitting." 28 | exit 1 29 | fi 30 | 31 | ARG_OVERWRITE="" 32 | if [[ -n ${INPUT_OVERWRITE} ]]; then 33 | ARG_OVERWRITE="--overwrite true" 34 | fi 35 | 36 | EXTRA_ARGS="" 37 | if [[ -n ${INPUT_EXTRA_ARGS} ]]; then 38 | EXTRA_ARGS=${INPUT_EXTRA_ARGS} 39 | fi 40 | 41 | VERB="upload-batch" 42 | CONTAINER_NAME_FLAG="--destination" 43 | if [[ -n ${INPUT_SYNC} ]]; then 44 | VERB="sync" 45 | CONTAINER_NAME_FLAG="--container" 46 | fi 47 | 48 | CLI_VERSION="" 49 | if [[ -n ${INPUT_CLI_VERSION} ]]; then 50 | CLI_VERSION="==${INPUT_CLI_VERSION}" 51 | fi 52 | 53 | az storage blob ${VERB} ${CONNECTION_METHOD} --source ${INPUT_SOURCE_DIR} ${CONTAINER_NAME_FLAG} ${INPUT_CONTAINER_NAME} ${ARG_OVERWRITE} ${EXTRA_ARGS} 54 | --------------------------------------------------------------------------------