Skip to content

Example GitHub action to upload file(s) to Azure Blob Storage

License

Notifications You must be signed in to change notification settings

berberich/upload-azure-blob

 
 

Repository files navigation

typescript-action status

Upload Blob to Azure Storage

This is an example GitHub action built in TypeScript that uploads file(s) to Azure Blob Storage, a "massively scalable and secure object storage for cloud-native workloads, archives, data lakes, high-performance computing, and machine learning".

Note: this action is meant solely for demonstration purposes. Best viewed together with the accompanying blog post.

For more about GitHub Actions, refer to the documentation.

Pre-reqs

  • Use an existing Azure account or sign up for a free account
  • Make sure you have access to a new or existing resource group, storage account, and container – for example, by following the first few steps of this quickstart
  • Then, configure credentials that can write Azure Storage containers and blobs, like a service principal with the "Storage Blob Data Contributor" role.
az ad sp create-for-rbac 
  --name $SP_NAME
  --sdk-auth
  --role "Storage Blob Data Contributor"
  --scopes /subscriptions/$SUBSCRIPTION_ID/resourceGroups/$RESOURCE_GROUP_NAME
  • Finally, store these credentials as a secret named AZURE_CREDENTIALS

Usage

Simple example:

# GitHub Actions repository workflow file, e.g .github/workflows/upload.yml

# ...
# previous steps to choose a runner type, prepare files, etc
# ...

- uses: azure/login@v1
  with:
    creds: ${{ secrets.AZURE_CREDENTIALS }}

# Upload `.png`s to Azure Blob Storage
- name: Upload all PNGs to Azure Blob Storage
  id: upload
  uses: github-developer/upload-azure-blob@v1
  with:
    account: octodex
    destination: octocats
    source: '**/*.png'

# Print out the urls to uploaded files
- name: Print URLs
  run: echo $URLS # { ["filename":"hulatocat.png","url":"https://octodex.blob.core.windows.net/octocats/hulatocat.png"] }
  env:
    URLS: ${{ steps.upload.outputs.urls }}

# ...

Inputs

  • account (required): Storage account name, e.g. mystorageaccount
  • destination (required): Name of container to upload blob to, e.g. $web to upload a static website.
  • source (required): Path to file(s) to upload to destination, e.g. . to upload all files in the current directory. Supports globbing, e.g. images/**.png. For more information, please refer to https://www.npmjs.com/package/glob.

Outputs

  • urls: data structure with names and urls to uploaded files

License

MIT

Contributing

Pull requests are welcome! See CONTRIBUTING.md for more.

About

Example GitHub action to upload file(s) to Azure Blob Storage

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 95.4%
  • JavaScript 4.6%