Skip to content

Commit

Permalink
Skip download if specified staet file does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Rindrics committed May 23, 2024
1 parent f549e75 commit 1a42099
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,26 @@ runs:
exit 1
fi
- name: Perform action
- name: Perform action
run: |
if [ "${{ inputs.action }}" = "download" ]; then
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ inputs.token }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ inputs.state_repo }}/contents/${{ inputs.state_path_remote }} > ${{ inputs.state_path_local }}.response
jq -r '.content' ${{ inputs.state_path_local }}.response | base64 --decode > ${{ inputs.state_path_local }}
echo "sha=$(jq -r '.sha' ${{ inputs.state_path_local }}" >> $GITHUB_OUTPUT
-o ${{ inputs.state_path_local }}.response \
-w "%{http_code}" \
https://api.github.com/repos/${{ inputs.state_repo }}/contents/${{ inputs.state_path_remote }} > response_code
HTTP_CODE=$(cat response_code)
if [ "$HTTP_CODE" -eq 200 ]; then
jq -r '.content' ${{ inputs.state_path_local }}.response | base64 --decode > ${{ inputs.state_path_local }}
echo "sha=$(jq -r '.sha' ${{ inputs.state_path_local }}.response)" >> $GITHUB_OUTPUT
elif [ "$HTTP_CODE" -eq 404 ]; then
echo "File not found, skipping download."
else
echo "Error: Received HTTP code $HTTP_CODE" >&2
exit 1
fi
elif [ "${{ inputs.action }}" = "upload" ]; then
if [ -z "${{ inputs.sha }}" ]; then
echo "Error: sha input is required for upload action" >&2
Expand Down

0 comments on commit 1a42099

Please sign in to comment.