aboutsummaryrefslogtreecommitdiffstats
path: root/.github/actions/s3cmd/action.yml
blob: 5166783bb27618f603ff60518c6e5bae51bb5b3d (plain) (blame)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
name: configure s3cmd
description: configure s3cmd
inputs:
  s3_key_id:
    required: true
    description: "s3 key id"
  s3_key_secret:
    required: true
    description: "s3 key secret"
  s3_bucket:
    required: false
    description: "s3 bucket"
  s3_endpoint:
    required: true
    description: "s3 endpoint"
  folder_prefix:
    required: false
    description: "folder prefix"
  build_preset:
    required: false
    description: "build preset like relwithdebinfo"
runs:
  using: "composite"
  steps:
    - name: configure s3cmd
      shell: bash
      run: |
        export S3CMD_CONFIG=$(mktemp)
        echo "S3CMD_CONFIG=$S3CMD_CONFIG" >> $GITHUB_ENV
        cat <<EOF > $S3CMD_CONFIG
        [default]
        access_key = ${s3_key_id}
        secret_key = ${s3_secret_access_key}
        bucket_location = ru-central1
        host_base = storage.yandexcloud.net
        host_bucket = %(bucket)s.storage.yandexcloud.net
        EOF

        # specify mime type for correct content-type in s3cmd sync 
        # we want to .out/.err files treat as text
        MIME_TYPES_LINE="text/plain                                      out err log"
        MIME_TYPES_FILE='/etc/mime.types'
        # add if not exists
        sudo bash -c "grep -qF -- '$MIME_TYPES_LINE' '$MIME_TYPES_FILE' || echo '$MIME_TYPES_LINE' >> '$MIME_TYPES_FILE'"
      env:
        s3_key_id: ${{ inputs.s3_key_id }}
        s3_secret_access_key: ${{ inputs.s3_key_secret }}

    - name: export s3 path variables
      shell: bash
      if: inputs.build_preset
      run: |
        folder="${{ runner.arch == 'X64' && 'x86-64' || runner.arch == 'ARM64' && 'arm64' || 'unknown' }}"
        
        BUILD_PRESET="${{ inputs.build_preset }}"
        
        case "$BUILD_PRESET" in
          relwithdebinfo)
            ;;
          debug)
            folder+="-debug"
            ;;
          release*)
            folder+="-${BUILD_PRESET/release-/}"
            ;;
          *)
            echo "Invalid preset: ${{ inputs.build_preset }}"
            exit 1
            ;;
        esac
        echo "S3_BUCKET_PATH=s3://${{ inputs.s3_bucket }}/${{ github.repository }}/${{github.workflow}}/${{ github.run_id }}/${{ inputs.folder_prefix }}${folder}" >> $GITHUB_ENV
        echo "S3_URL_PREFIX=${{ inputs.s3_endpoint }}/${{ inputs.s3_bucket }}/${{ github.repository }}/${{ github.workflow }}/${{ github.run_id }}/${{ inputs.folder_prefix }}${folder}" >> $GITHUB_ENV
        echo "S3_TEST_ARTIFACTS_BUCKET_PATH=s3://${{ inputs.s3_bucket }}/testing_out_stuff/${{ github.repository }}/${{github.workflow}}/${{ github.run_id }}/${{ inputs.folder_prefix }}${folder}" >> $GITHUB_ENV
        echo "S3_TEST_ARTIFACTS_URL_PREFIX=${{ inputs.s3_endpoint }}/${{ inputs.s3_bucket }}/testing_out_stuff/${{ github.repository }}/${{ github.workflow }}/${{ github.run_id }}/${{ inputs.folder_prefix }}${folder}" >> $GITHUB_ENV