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.
- 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
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@v1with:
creds: ${{ secrets.AZURE_CREDENTIALS }}# Upload `.png`s to Azure Blob Storage
- name: Upload all PNGs to Azure Blob Storageid: uploaduses: github-developer/upload-azure-blob@v1with:
account: octodexdestination: octocatssource: '**/*.png'# Print out the urls to uploaded files
- name: Print URLsrun: echo $URLS # { ["filename":"hulatocat.png","url":"https://octodex.blob.core.windows.net/octocats/hulatocat.png"] }env:
URLS: ${{ steps.upload.outputs.urls }}# ...account(required): Storage account name, e.g.mystorageaccountdestination(required): Name of container to upload blob to, e.g.$webto upload a static website.source(required): Path to file(s) to upload todestination, 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.
urls: data structure with names and urls to uploaded files
Pull requests are welcome! See CONTRIBUTING.md for more.