Skip to content

Download from R2

This Composite Action downloads an artifact from Cloudflare R2.

R2 download artifact

- uses: Yellow-Dog-Man/composite-actions-templates/.github/actions/download-from-r2@main
  with:
    r2-storage-bucket: (1)
    r2-api-id: (2)
    r2-auth-token-id: (3)
    r2-auth-token: (4)
    r2-region: (5)
    r2-path: (6)
    put-path: (7)
  1. Storage bucket to use to store the artifacts

  2. Account ID for R2

  3. ID of the authentication token for R2

  4. Authentication token for R2

  5. Region for the R2 account

  6. Path within R2 where to put the file.

  7. File path where to put the files.

Downloads an artifact from R2.

Inputs: ¤

Name Description
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.

put-path

File path where to put the files.

Outputs: ¤

Name Description
cache-hit

Returns if the cache was hit or not.

Source of Yellow-Dog-Man/composite-actions-templates/.github/actions/download-from-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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
name: 'R2 download artifact'
description: 'Downloads an artifact from R2.'

inputs:
  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
  put-path:
    description: 'File path where to put the files.'
    required: true

outputs:
  cache-hit:
    description: 'Returns if the cache was hit or not.'
    value: ${{ steps.cache-status.outputs.status }}

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

    - name: 'Get the file'
      shell: bash
      id: s3get
      continue-on-error: true
      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 get s3://${{ inputs.r2-storage-bucket }}/github/${{ inputs.r2-path }}/files.tar.zstd .

    - name: 'Decompress file to path'
      shell: bash
      id: decomp
      continue-on-error: true
      run: tar -xf files.tar.zstd -C ${{ inputs.put-path }}

    - name: 'Return cache success'
      shell: bash
      id: cache-status
      run: |
        if [ "${{ steps.s3get.conclusion }}" != "success" ] || [ "${{ steps.decomp.conclusion }}" != "success" ]; then
          echo "status=false" >> $GITHUB_ENV
        else
          echo "status=true" >> $GITHUB_ENV
        fi