- job:
    name: jdkX-jcstress-test-persist-results
    project-type: matrix
    defaults: global
    description: |
        * Writes results to:<br>
          * /work/openjdk-testing/jcstress-nightly-runs<br>
          * /work/openjdk-testing/jcstress-results
    properties:
        - authorization:
            everyone-flat:
                - job-read
            openjdk-members:
                - job-extended-read
                - job-build
                - job-cancel
        - build-discarder:
            days-to-keep: 30
            num-to-keep: 10
            artifact-num-to-keep: 5
    parameters:
        - string:
            name: YEAR
            default: 'default'
        - string:
            name: DAY_OF_YEAR
            default: 'default'
    disabled: true
    node: j12-qrep-01
    display-name: 'DELETE ME'
    axes:
        - axis:
            type: user-defined
            name: BUILD_TYPE
            values:
                - release
        - axis:
            type: slave
            name: label
            values:
                - j12-qrep-01
    execution-strategy:
        sequential: true
    wrappers:
        - workspace-cleanup:
            dirmatch: false
        - timestamps
        - matrix-tie-parent:
            node: j12-qrep-01
    builders:
        - copyartifact:
            project: jdkX-update-src-tree
            filter: 'out/build-date.sh'
            target: incoming
            flatten: true
        - copyartifact:
            project: jdkX-jcstress-test
            filter: 'out/jcstress-results-${BUILD_TYPE}.tar.gz'
            target: incoming
            flatten: true
        - shell: |
            #!/bin/bash

            set -exu

            PERSIST=$HOME/srv/openjdkX

            : ${YEAR:=$(date +%Y)}
            : ${DAY_OF_YEAR:=$(date +%j)}

            JCSTRESS_RUN_DIR=$PERSIST/jcstress-nightly-runs
            JCSTRESS_RESULTS_DIR=$PERSIST/jcstress-results
            RESULTS_CSV=${JCSTRESS_RESULTS_DIR}/results.csv

            mkdir -p $JCSTRESS_RESULTS_DIR

            # Tolerate missing results.csv file.
            if [ ! -f $RESULTS_CSV ]; then
                touch $RESULTS_CSV
            fi

            mkdir -p ${JCSTRESS_RESULTS_DIR} ${JCSTRESS_RUN_DIR}/${YEAR}/${DAY_OF_YEAR}
            tar -C ${JCSTRESS_RUN_DIR}/${YEAR}/${DAY_OF_YEAR} --strip-components=1 -xzf incoming/BUILD_TYPE=${BUILD_TYPE},label=${label}/jcstress-results-${BUILD_TYPE}.tar.gz
            numeric_date=$(date +'%s' --date=$(date +'%Y-%m-%d'))
            echo "Previous Results"
            cat ${RESULTS_CSV}
            echo "${numeric_date},${JCSTRESS_RUN_DIR}/${YEAR}/${DAY_OF_YEAR},success" >> ${RESULTS_CSV}
            sort --unique --field-separator=',' --numeric-sort -o ${RESULTS_CSV} ${RESULTS_CSV}

