github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/pkg/projectfile/nameval_data_test.go (about)

     1  package projectfile
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  )
     7  
     8  var (
     9  	pFileYAMLValid = pFileYAML{"CLI_BUILDFLAGS", "-ldflags=\"-s -w\""}
    10  )
    11  
    12  type pFileYAML struct {
    13  	firstKey, firstVal string
    14  }
    15  
    16  func (y pFileYAML) asLongYAML() []byte {
    17  	return applyToYAML(`
    18  project: https://platform.activestate.com/ActiveState/cli?branch=main
    19  constants:
    20    - name: %s
    21      value: %s
    22    - name: CLI_PKGS
    23      value: ./cmd/state
    24    - name: SET_ENV
    25      description: The environment settings used throughout our project
    26      value: |
    27        GOFLAGS='-mod=vendor'
    28        BUILD_TARGET_DIR=$constants.BUILD_TARGET_PREFIX_DIR/${GOARCH#amd64}
    29    - name: SCRIPT_EXT
    30      if: ne .OS.Name "Windows"
    31      value: .sh
    32  scripts:
    33    - name: preprocess
    34      language: bash
    35      description: Generates assets required by the project that aren't just specific to the build
    36      value: |
    37        $constants.SET_ENV
    38        go run scripts/constants-generator/main.go -- internal/constants/generated.go
    39    - name: build
    40      language: bash
    41      description: Builds the project with the host OS as the target OS.
    42      value: |
    43        $constants.SET_ENV
    44        go build -tags "$GO_BUILD_TAGS" -o $BUILD_TARGET_DIR/$constants.BUILD_TARGET $constants.CLI_BUILDFLAGS $constants.CLI_PKGS
    45  events:
    46    - name: activate
    47      value: |
    48        if ! type "go" &> /dev/null; then
    49          echo "go is not installed. Please install Go version 1.11 or above."
    50          exit 1
    51        fi
    52        git config core.hooksPath .githooks
    53    - name: file-changed
    54      scope: ["internal/locale/locales"]
    55      value: build
    56  `, y)
    57  }
    58  
    59  func (y pFileYAML) asShortYAML() []byte {
    60  	return applyToYAML(`
    61  project: https://platform.activestate.com/ActiveState/cli?branch=main
    62  constants:
    63    - %s: %s
    64    - CLI_PKGS: ./cmd/state
    65    - SET_ENV: |
    66        GOFLAGS='-mod=vendor'
    67        BUILD_TARGET_DIR=$constants.BUILD_TARGET_PREFIX_DIR/${GOARCH#amd64}
    68    - name: SCRIPT_EXT
    69      if: ne .OS.Name "Windows"
    70      value: .sh
    71  scripts:
    72    - preprocess: |
    73        $constants.SET_ENV
    74        go run scripts/constants-generator/main.go -- internal/constants/generated.go
    75    - build: |
    76        $constants.SET_ENV
    77        go build -tags "$GO_BUILD_TAGS" -o $BUILD_TARGET_DIR/$constants.BUILD_TARGET $constants.CLI_BUILDFLAGS $constants.CLI_PKGS
    78  events:
    79    - activate: |
    80        if ! type "go" &> /dev/null; then
    81          echo "go is not installed. Please install Go version 1.11 or above."
    82          exit 1
    83        fi
    84        git config core.hooksPath .githooks
    85    - name: file-changed
    86      scope: ["internal/locale/locales"]
    87      value: build
    88  `, y)
    89  }
    90  
    91  func applyToYAML(d string, vs pFileYAML) []byte {
    92  	return []byte(fmt.Sprintf(strings.TrimSpace(d)+"\n", vs.firstKey, vs.firstVal))
    93  }