@@ -106,26 +106,48 @@ jobs:
106106 grep -i "missing," "$ARTIFACT_DIR/report.csv" | cut -f2 -d',' > "$STATE_DIR/last-failures" || true
107107 echo "TODAY=$TODAY" >> "$GITHUB_ENV"
108108
109+ - name : Evaluate report and failures
110+ run : |
111+ set -euo pipefail
112+ REPORT="$ARTIFACT_DIR/report.csv"
113+ VALIDATION_ERRORS=0
114+ if [[ -f "$REPORT" ]]; then
115+ VALIDATION_ERRORS=$(grep -Eci "validation|missing|failed" "$REPORT" || true)
116+ fi
117+ echo "VALIDATION_ERRORS=$VALIDATION_ERRORS" >> "$GITHUB_ENV"
118+
109119 - name : Upload to Portico FTP
110120 run : |
111121 # Note #1: the file redirection is to avoid wc printing the file name.
112122 # Note #2: the -gt 1 is to skip the header line when counting the lines.
123+ set -u
124+ CURL_STATUS=0
113125 LINES=$(wc -l < "$ARTIFACT_DIR/report.csv")
114126 if [[ $LINES -gt 1 ]]; then
115127 ARCHIVEFILE="$ARTIFACT_DIR/micropublication-org.zip"
116128 if [[ -f "$ARCHIVEFILE" ]]; then
117129 echo "=== FTP'ing file to Portico ===" | tee -a "$ARTIFACT_DIR/run.log"
130+ set +e
118131 curl -k -T "$ARCHIVEFILE" ${{ vars.PORTICO_FTP_ADDRESS }} \
119132 --user ${{ secrets.PORTICO_USER }}:${{ secrets.PORTICO_PASS }} 2>&1 | tee -a "$ARTIFACT_DIR/run.log"
120- # Discard the zip file after successful upload
133+ CURL_STATUS=${PIPESTATUS[0]}
134+ set -e
135+ # Discard the zip file.
121136 rm -f "$ARCHIVEFILE"
122137 fi
123138 fi
124- # If we get this far, write out a date stamp file to indicate that things
125- # ran successfully and to give the next run a starting point.
126- echo "$TODAY" > ".github/state/archive-in-portico/last-run-date"
139+ echo "CURL_STATUS=$CURL_STATUS" >> "$GITHUB_ENV"
140+
141+ - name : Update state files
142+ if : ${{ env.VALIDATION_ERRORS == '0' && env.CURL_STATUS == '0' }}
143+ run : |
144+ STATE_DIR=".github/state/archive-in-portico"
145+ mkdir -p "$STATE_DIR"
146+ grep -i "missing," "$ARTIFACT_DIR/report.csv" | cut -f2 -d',' > "$STATE_DIR/last-failures" || true
147+ echo "$TODAY" > "$STATE_DIR/last-run-date"
127148
128149 - name : Commit updated state files
150+ if : ${{ env.VALIDATION_ERRORS == '0' && env.CURL_STATUS == '0' }}
129151 run : |
130152 git config user.name "github-actions[bot]"
131153 git config user.email "github-actions[bot]@users.noreply.github.com"
@@ -141,10 +163,13 @@ jobs:
141163 MAILGUN_API_KEY : ${{ secrets.MAILGUN_API_KEY }}
142164 MAILGUN_DOMAIN : ${{ vars.MAILGUN_DOMAIN }}
143165 RUN_NAME : " Portico archiving"
166+ VALIDATION_ERRORS : ${{ env.VALIDATION_ERRORS }}
167+ CURL_STATUS : ${{ env.CURL_STATUS }}
144168 run : |
145169 bash .github/scripts/mailgun.sh "${{ env.ARTIFACT_DIR }}"
146170
147171 - name : Install slack-cli
172+ if : always()
148173 run : |
149174 git clone --depth 1 https://github.com/caltechlibrary/slack-cli "$RUNNER_TEMP/slack-cli"
150175 echo "$RUNNER_TEMP/slack-cli/src" >> "$GITHUB_PATH"
@@ -155,10 +180,13 @@ jobs:
155180 SLACK_CHANNEL : ${{ vars.SLACK_CHANNEL }}
156181 SLACK_CLI_TOKEN : ${{ secrets.SLACK_CLI_TOKEN }}
157182 RUN_NAME : " Portico run for micropublications.org"
183+ VALIDATION_ERRORS : ${{ env.VALIDATION_ERRORS }}
184+ CURL_STATUS : ${{ env.CURL_STATUS }}
158185 run : |
159186 bash .github/scripts/slack.sh "${{ env.ARTIFACT_DIR }}"
160187
161188 - name : Upload artifact
189+ if : always()
162190 uses : actions/upload-artifact@v6
163191 with :
164192 path : ${{ env.ARTIFACT_DIR }}
0 commit comments