Skip to content

Upload to R2

This Composite Action uploads an artifact to Cloudflare R2.

R2 upload artifact

- uses: Yellow-Dog-Man/composite-actions-templates/.github/actions/upload-to-r2@main
  with:
    file-path: (1)
    r2-storage-bucket: (2)
    r2-api-id: (3)
    r2-auth-token-id: (4)
    r2-auth-token: (5)
    r2-region: (6)
    r2-path: (7)
  1. Path to the file being uploaded

  2. Storage bucket to use to store the artifacts

  3. Account ID for R2

  4. ID of the authentication token for R2

  5. Authentication token for R2

  6. Region for the R2 account

  7. Path within R2 where to put the file.

Uploads a directory to R2.

Inputs: ยค

Name Description
file-path

Path to the file being uploaded

r2-storage-bucket

Storage bucket to use to store the artifacts

r2-api-id

Account ID for R2

r2-auth-token-id

ID of the authentication token for R2

r2-auth-token

Authentication token for R2

r2-region

Region for the R2 account

r2-path

Path within R2 where to put the file.

Source of Yellow-Dog-Man/composite-actions-templates/.github/actions/upload-to-r2@main
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
name: 'R2 upload artifact'
description: 'Uploads a directory to R2.'

inputs:
  file-path:
    description: 'Path to the file being uploaded'
    required: true
  r2-storage-bucket:
    description: 'Storage bucket to use to store the artifacts'
    required: true
  r2-api-id:
    description: 'Account ID for R2'
    required: true
  r2-auth-token-id:
    description: 'ID of the authentication token for R2'
    required: true
  r2-auth-token:
    description: 'Authentication token for R2'
    required: true
  r2-region:
    description: 'Region for the R2 account'
    required: true
  r2-path:
    description: 'Path within R2 where to put the file.'
    required: true

runs:
  using: composite
  steps:
    - name: 'Install dependencies'
      shell: bash
      run: |
        apt-get update
        apt-get install -y s3cmd

    - name: 'Generate zip for files'
      shell: bash
      run: tar --zstd -cf files.tar.zstd -C ${{ inputs.file-path }} .

    - name: 'Generate destination dir'
      id: dest-dir
      shell: bash
      run: echo "directory=github/${{ inputs.r2-path }}" >> $GITHUB_OUTPUT

    - name: 'Upload files to bucket'
      shell: bash
      run: s3cmd --access_key=${{ inputs.r2-auth-token-id }} --secret_key=${{ inputs.r2-auth-token }} --region=${{ inputs.r2-region }} --host=https://${{ inputs.r2-api-id }}.r2.cloudflarestorage.com put files.tar.zstd s3://${{ inputs.r2-storage-bucket }}/${{ steps.dest-dir.outputs.directory }}/