github.com/jfrog/jfrog-cli-core/v2@v2.51.0/general/cisetup/githubactionsfilegenerator.go (about) 1 package cisetup 2 3 import ( 4 "fmt" 5 "path/filepath" 6 "strings" 7 8 "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils" 9 ) 10 11 var GithubActionsDir = filepath.Join(".github", "workflows") 12 var GithubActionsFilePath = filepath.Join(GithubActionsDir, GithubActionsFileName) 13 14 const GithubActionsFileName = "build.yml" 15 const githubActionsTemplate = ` 16 name: 'JFrog CI Integration' 17 on: [push] 18 jobs: 19 jfrog-ci-integration: 20 runs-on: ubuntu-latest 21 env: 22 JF_ARTIFACTORY_1: ${{ secrets.JF_ARTIFACTORY_SECRET_1 }} 23 JFROG_BUILD_STATUS: PASS 24 steps: 25 - name: Checkout 26 uses: actions/checkout@v2 27 - name: Setup JFrog CLI 28 uses: jfrog/setup-jfrog-cli@v1 29 - name: Set up JDK 11 30 uses: actions/setup-java@v2 31 with: 32 java-version: '11' 33 distribution: 'adopt' 34 - name: Build 35 run: | 36 # Configure the project 37 %s 38 # Build the project using JFrog CLI 39 %s 40 - name: Failure check 41 run: | 42 echo "JFROG_BUILD_STATUS=FAIL" >> $GITHUB_ENV 43 if: failure() 44 - name: Publish build 45 run: | 46 # Collect and store environment variables in the build-info 47 jfrog rt bce 48 # Collect and store VCS details in the build-info 49 jfrog rt bag 50 # Publish the build-info to Artifactory 51 jfrog rt bp 52 # Scan the published build-info with Xray 53 jfrog rt bs 54 if: always()` 55 56 type GithubActionsGenerator struct { 57 SetupData *CiSetupData 58 } 59 60 func (gg *GithubActionsGenerator) Generate() (githubActionsBytes []byte, githubActionsName string, err error) { 61 // setM2 env variable if maven is used. 62 setM2 := gg.SetupData.BuiltTechnology.Type == coreutils.Maven 63 buildToolsConfigCommands := strings.Join(getTechConfigsCommands(ConfigServerId, setM2, gg.SetupData), "\n ") 64 buildCommand, err := convertBuildCmd(gg.SetupData) 65 if err != nil { 66 return nil, "", err 67 } 68 return []byte(fmt.Sprintf(githubActionsTemplate, buildToolsConfigCommands, buildCommand)), GithubActionsFileName, nil 69 }