diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d64c025..4fd374d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -66,7 +66,7 @@ env: git_upstream: >- { "coatjava": { "fork": "JeffersonLab/coatjava", "ref": "development" }, - "clas12Tags": { "fork": "gemc/clas12Tags", "ref": "5.4" }, + "clas12Tags": { "fork": "gemc/clas12Tags", "ref": "" }, "clas12-config": { "fork": "JeffersonLab/clas12-config", "ref": "main" }, "clas12-validation": { "fork": "JeffersonLab/clas12-validation", "ref": "main" } } @@ -124,8 +124,15 @@ jobs: ref_clas12config: ${{ steps.info.outputs.ref_clas12config }} fork_clas12validation: ${{ steps.info.outputs.fork_clas12validation }} ref_clas12validation: ${{ steps.info.outputs.ref_clas12validation }} + gemc_module_tag: ${{ steps.gemc_module_tag.outputs.gemc_module_tag }} + gemc_executable: ${{ steps.gemc_executable.outputs.gemc_executable }} + caller_repo: ${{ steps.gemc_executable.outputs.caller_repo }} steps: - - uses: actions/checkout@v4 + - name: checkout clas12-validation + uses: actions/checkout@v4 + with: + repository: JeffersonLab/clas12-validation + # ref: feature-branch # NOTE: if making a clas12-validation change that impacts this job, temporarily set the corresponding ref here - name: get dependency info id: info run: | @@ -143,10 +150,10 @@ jobs: ref_clas12config=$(jq -r '."clas12-config".ref' deps.json) ref_clas12validation=$(jq -r '."clas12-validation".ref' deps.json) ### if any ref names are empty strings, use the highest tag instead - [ "$ref_coatjava" = "" ] && ref_coatjava=$(bin/get_highest_tag.rb $fork_coatjava) - [ "$ref_clas12tags" = "" ] && ref_clas12tags=$(bin/get_highest_tag.rb $fork_clas12tags) - [ "$ref_clas12config" = "" ] && ref_clas12config=$(bin/get_highest_tag.rb $fork_clas12config) - [ "$ref_clas12validation" = "" ] && ref_clas12validation=$(bin/get_highest_tag.rb $fork_clas12validation) + [ "$ref_coatjava" = "" ] && ref_coatjava=$(bin/get_highest_tag.rb JeffersonLab/coatjava) # NOTE: using the main forks here, since they have the semver tags + [ "$ref_clas12tags" = "" ] && ref_clas12tags=$(bin/get_highest_tag.rb gemc/clas12Tags) + [ "$ref_clas12config" = "" ] && ref_clas12config=$(bin/get_highest_tag.rb JeffersonLab/clas12-config) + [ "$ref_clas12validation" = "" ] && ref_clas12validation=$(bin/get_highest_tag.rb JeffersonLab/clas12-validation) ### set output vars echo fork_coatjava=$fork_coatjava >> $GITHUB_OUTPUT echo fork_clas12tags=$fork_clas12tags >> $GITHUB_OUTPUT @@ -156,6 +163,23 @@ jobs: echo ref_clas12tags=$ref_clas12tags >> $GITHUB_OUTPUT echo ref_clas12config=$ref_clas12config >> $GITHUB_OUTPUT echo ref_clas12validation=$ref_clas12validation >> $GITHUB_OUTPUT + - name: set GEMC module tag + id: gemc_module_tag + run: | + ### if `ref_clas12tags` is a tag, use that; otherwise use the highest semver tag + ### FIXME probably won't work for triggers from backports to old `clas12Tags` tags + gemc_module_tag=${{ steps.info.outputs.ref_clas12tags }} + repo=gemc/clas12Tags + bin/is_a_tag.rb $gemc_module_tag $repo || gemc_module_tag=$(bin/get_highest_tag.rb $repo) + echo gemc_module_tag=$gemc_module_tag >> $GITHUB_OUTPUT + - name: set GEMC executable + id: gemc_executable + run: | + ### if the caller repo is `clas12Tags`, we want to locally build GEMC; if not, use the container version + caller_repo=$(echo "${{ github.repository }}" | sed 's;^.*/;;g') + [ "$caller_repo" = "clas12Tags" ] && gemc_executable=./clas12Tags/source/gemc || gemc_executable=gemc + echo gemc_executable=$gemc_executable >> $GITHUB_OUTPUT + echo caller_repo=$caller_repo >> $GITHUB_OUTPUT - name: dispatch summary run: | msg=$(echo '${{ github.event.pull_request.title || github.event.head_commit.message }}' | head -n1) @@ -167,6 +191,10 @@ jobs: echo '| **`clas12-config` Fork and Ref:** | `${{ steps.info.outputs.fork_clas12config }}` | [`${{ steps.info.outputs.ref_clas12config }}`](https://github.com/${{ steps.info.outputs.fork_clas12config }}/tree/${{ steps.info.outputs.ref_clas12config }}) |' >> $GITHUB_STEP_SUMMARY echo '| **`clas12-validation` Fork and Ref:** | `${{ steps.info.outputs.fork_clas12validation }}` | [`${{ steps.info.outputs.ref_clas12validation }}`](https://github.com/${{ steps.info.outputs.fork_clas12validation }}/tree/${{ steps.info.outputs.ref_clas12validation }}) |' >> $GITHUB_STEP_SUMMARY echo '| | | |' >> $GITHUB_STEP_SUMMARY + echo '' >> $GITHUB_STEP_SUMMARY + echo '- Caller repository: `${{ steps.gemc_executable.outputs.caller_repo }}`' >> $GITHUB_STEP_SUMMARY + echo '- GEMC module: `gemc/${{ steps.gemc_module_tag.outputs.gemc_module_tag }}`' >> $GITHUB_STEP_SUMMARY + echo '- GEMC executable: `${{ steps.gemc_executable.outputs.gemc_executable }}`' >> $GITHUB_STEP_SUMMARY # build ############################################################################# @@ -206,6 +234,7 @@ jobs: build_gemc: name: Build GEMC + if: ${{ needs.dependency_info.outputs.caller_repo == 'clas12Tags' }} # only build GEMC if triggered by GEMC/clas12Tags needs: - dependency_info runs-on: ubuntu-latest @@ -228,10 +257,10 @@ jobs: fetch-tags: true fetch-depth: 0 - name: build - uses: docker://jeffersonlab/gemc:4.4.2-5.4-5.5-fedora36 ##### FIXME: need `latest` tag + uses: docker://jeffersonlab/gemc:dev-fedora36 with: - entrypoint: bin/ci_gemc.sh ##### FIXME (in the script): switch to gemc/dev and use ubuntu + cvmfs action - args: build clas12Tags/source + entrypoint: bin/ci_gemc_build.sh + args: clas12Tags/source - name: tar run: tar cavf clas12Tags{.tar.zst,} - uses: actions/upload-artifact@v4 @@ -408,6 +437,7 @@ jobs: ############################################################################# fulltest: name: Run + if: ${{ ! failure() && ! cancelled() }} # needed since `build_gemc` may be skipped needs: - event_generation - build_gemc @@ -457,10 +487,10 @@ jobs: ls ${{ steps.files.outputs.gemcConfigFile }} ls ${{ steps.files.outputs.coatjavaConfigFile }} - name: simulation - uses: docker://jeffersonlab/gemc:4.4.2-5.4-5.5-fedora36 ##### FIXME: need `latest` tag + uses: docker://jeffersonlab/gemc:dev-fedora36 with: - entrypoint: bin/ci_gemc.sh ##### FIXME (in the script): switch to gemc/dev and use ubuntu + cvmfs action - args: sim clas12Tags/source ${{ steps.files.outputs.gemcConfigFile }} ${{ steps.files.outputs.evgenFile }} ${{ steps.files.outputs.simFile }} + entrypoint: bin/ci_gemc_run.sh + args: ${{ needs.dependency_info.outputs.gemc_executable }} ${{ needs.dependency_info.outputs.gemc_module_tag }} ${{ steps.files.outputs.gemcConfigFile }} ${{ steps.files.outputs.evgenFile }} ${{ steps.files.outputs.simFile }} - name: check if output exists run: ls ${{ steps.files.outputs.simFile }} - name: reconstruction @@ -497,6 +527,7 @@ jobs: ############################################################################# final: name: Final + if: ${{ ! failure() && ! cancelled() }} # needed since `build_gemc` may be skipped needs: - fulltest - config_files @@ -529,13 +560,13 @@ jobs: issue_bot: name: Issue bot + if: ${{ github.event_name == 'schedule' && ( cancelled() || failure() ) }} runs-on: ubuntu-latest needs: - final permissions: contents: read issues: write - if: ${{ github.event_name == 'schedule' && ( cancelled() || failure() ) }} steps: - uses: actions/checkout@v4 - uses: JasonEtco/create-an-issue@v2 diff --git a/bin/ci_gemc.sh b/bin/ci_gemc.sh deleted file mode 100755 index a8d0c42..0000000 --- a/bin/ci_gemc.sh +++ /dev/null @@ -1,79 +0,0 @@ -#!/bin/bash -# CI `gemc` wrapper for CI workflow steps when `uses: [CONTAINER]` is used, -# which does not seem to be compatible with multi-line commands - -set -e -set -u - -### usage -if [ $# -eq 0 ]; then - echo """ - USAGE: $0 [command] [ARGS]... - commands: - - build compile GEMC - ARGS: [source_dir] - - sim run GEMC - ARGS: [source_dir] [config] [input] [output] - - """ >&2 - exit 2 -fi -cmd=$1 -shift - -### parse arguments -case $cmd in - build) - sourceDir=$1 - ;; - sim) - sourceDir=$1 - gemcConfigFile=$2 - evgenFile=$3 - simFile=$4 - ;; - *) - echo "ERROR: unknown command '$cmd'" >&2 - exit 1 - ;; -esac - -### source environment, and show available modules -set +u -source /app/localSetup.sh -set -u -echo "==============================" -echo "MODULE AVAIL" -echo "==============================" -module avail --no-pager -echo "==============================" - -### compile GEMC in $sourceDir -if [ "$cmd" = "build" ]; then - pushd $sourceDir - scons -j4 OPT=1 - popd -fi - -### to get the dependencies correct, switch to this tag -##### FIXME: switch to gemc/dev and use ubuntu + cvmfs action -module switch gemc/5.4 - -### run a simulation or print build info -case $cmd in - sim) - ### run a simulation - $sourceDir/gemc \ - $gemcConfigFile \ - -INPUT_GEN_FILE="LUND, $evgenFile" \ - -USE_GUI=0 \ - -OUTPUT="hipo, $simFile" - ;; - build) - ### print build info - echo "### GEMC Build Information:" - $sourceDir/gemc -USE_GUI=0 - ;; -esac diff --git a/bin/ci_gemc_build.sh b/bin/ci_gemc_build.sh new file mode 100755 index 0000000..b7d4cd5 --- /dev/null +++ b/bin/ci_gemc_build.sh @@ -0,0 +1,24 @@ +#!/bin/bash +# build GEMC wrapper + +set -e +set -u + +sourceDir=$1 + +### source environment +set +u +source /app/localSetup.sh +set -u + +### show available modules +echo "==============================" +echo "MODULE AVAIL" +echo "==============================" +module avail --no-pager +echo "==============================" + +### compile GEMC in $sourceDir +pushd $sourceDir +scons -j$(nproc) OPT=1 +popd diff --git a/bin/ci_gemc_run.sh b/bin/ci_gemc_run.sh new file mode 100755 index 0000000..9cc6cde --- /dev/null +++ b/bin/ci_gemc_run.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# run GEMC wrapper + +set -e +set -u + +gemcExe=$1 +gemcTag=$2 +gemcConfigFile=$3 +evgenFile=$4 +simFile=$5 + +### source environment +set +u +source /app/localSetup.sh +set -u + +### show available modules +echo "==============================" +echo "MODULE AVAIL" +echo "==============================" +module avail --no-pager +echo "==============================" + +### switch to the gemc module +### - if we do not have a custom build, this activates the appropriate gemc version +### - if we do have a custom build, this just makes sure the dependencies are resolved correctly +module switch gemc/$gemcTag + +### run a simulation +$gemcExe \ + $gemcConfigFile \ + -INPUT_GEN_FILE="LUND, $evgenFile" \ + -USE_GUI=0 \ + -OUTPUT="hipo, $simFile" diff --git a/bin/is_a_tag.rb b/bin/is_a_tag.rb new file mode 100755 index 0000000..75e6aa9 --- /dev/null +++ b/bin/is_a_tag.rb @@ -0,0 +1,23 @@ +#!/usr/bin/ruby +# check if a given tag is available in a repo; exit 0 if yes, 1 if no + +unless ARGV.length == 2 + $stderr.puts "USAGE: #{$0} [tag] [repo owner]/[repo name]" + exit 2 +end +check_tag, repo = ARGV + +api_args = [ + '--silent', + '-L', + '-H "Accept: application/vnd.github+json"', + '-H "X-GitHub-Api-Version: 2022-11-28"', + "https://api.github.com/repos/#{repo}/tags", +] +tag_list = `curl #{api_args.join ' '} | jq -r '.[].name'` +unless $?.success? + $stderr.puts "ERROR: failed to get list of tags from #{repo}" + exit 1 +end + +exit 1 unless tag_list.include? check_tag