cozy-labs/cozy-desktop

View on GitHub
.github/actions/setup-cozy-stack/action.yaml

Summary

Maintainability
Test Coverage
name: Setup cozy-stack
author: Erwan Guyader
description: Downloads cozy-stack, starts it and create a test instance.
inputs:
  couchdb-url:
    description: 'The fully qualified URL to make requests to CouchDB'
    required: true
  cozy-stack-storage:
    description: 'The folder location where the remote cozy-stack files will be stored'
    required: false
  cozy-passphrase:
    description: 'The user passphrase of the created Cozy instance'
    required: false
runs:
  using: composite
  steps:
    - name: Set env variables
      shell: bash
      run: |
        echo "COZY_COUCHDB_URL=${{ inputs.couchdb-url }}" >> $GITHUB_ENV

        if [[ -z $COZY_STACK_STORAGE ]]; then
          echo "COZY_STACK_STORAGE=${{ inputs.cozy-stack-storage }}" >> $GITHUB_ENV
        fi
        if [[ -z $COZY_URL ]]; then
          echo "COZY_URL=${{ inputs.cozy-url }}" >> $GITHUB_ENV
        fi
        if [[ -z $COZY_DOMAIN ]]; then
          echo "COZY_DOMAIN=${COZY_URL#http://}" >> $GITHUB_ENV
        fi
        if [[ -z $COZY_PASSPHRASE ]]; then
          echo "COZY_PASSPHRASE=${{ inputs.cozy-passphrase }}" >> $GITHUB_ENV
        fi
        if [[ -z $GOPATH ]]; then
          echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
        fi

    - name: Download cozy-stack's go.sum
      shell: bash
      run: |
          echo "Downloading cozy-stack's go.sum..."
          curl \
            -H 'Authorization: Bearer ${{ github.token }}' \
            -H 'Accept: application/vnd.github.v3.raw' \
            -L 'https://api.github.com/repos/cozy/cozy-stack/contents/go.sum' \
            -O
          echo "GOPATH: $GOPATH"

    - name: Cache Go dependencies
      id: cache-go-deps
      uses: actions/cache@v3
      env:
        cache-name: cache-go-deps
      with:
        path: |
          ${{ env.GOPATH }}
        key: ${{ runner.os }}-v${{ env.GO_VERSION }}-${{ env.cache-name }}-${{ hashFiles('go.sum') }}

    - name: Download cozy-stack
      if: ${{ steps.cache-go-deps.outputs.cache-hit != 'true' }}
      shell: bash
      run: go install github.com/cozy/cozy-stack@latest

    - name: Create cozy-stack storage
      shell: bash
      run: |
        if [ "${{ runner.os }}" != "macOS" ]; then
          echo "Creating cozy-stack storage folder $COZY_STACK_STORAGE..."
          mkdir -p $COZY_STACK_STORAGE
        fi

    - name: Create a local instance and an OAuth client
      shell: bash
      run: |
        echo "Starting cozy-stack..."
        if [ "${{ runner.os }}" == "macOS" ]; then
          cozy-stack serve --fs-url "swift+https://auth.cloud.ovh.net/v3?AuthURL=https%3A%2F%2Fauth.cloud.ovh.net%2Fv3&UserName=$OS_USERNAME&Password=$OS_PASSWORD&ProjectName=$OS_PROJECT_NAME&Region=GRA&UserDomainName=Default&Timeout={{ .Env.GOSWIFT_TIMEOUT }}" --log-level warning >cozy-stack.log 2>&1 &
        else
          cozy-stack serve --fs-url "file://$COZY_STACK_STORAGE" --log-level warning >cozy-stack.log 2>&1 &
        fi

        echo "Creating instance..."
        until cozy-stack instances add --passphrase "$COZY_PASSPHRASE" "$COZY_DOMAIN"
        do
          echo "Waiting for cozy-stack to be running..."
          sleep 1
        done

        echo "Creating OAuth client for tests..."
        COZY_CLIENT_ID=$(cozy-stack instances client-oauth "$COZY_DOMAIN" http://localhost/ test github.com/cozy-labs/cozy-desktop)
        echo "COZY_CLIENT_ID=$COZY_CLIENT_ID" >> $GITHUB_ENV

        echo "Getting OAuth token for tests..."
        COZY_STACK_TOKEN=$(cozy-stack instances token-oauth "$COZY_DOMAIN" "$COZY_CLIENT_ID" io.cozy.files io.cozy.settings)
        echo "COZY_STACK_TOKEN=$COZY_STACK_TOKEN" >> $GITHUB_ENV