Skip to content

Commit 49adb52

Browse files
Return correct action status in case of failure (#6)
1 parent e44656f commit 49adb52

File tree

4 files changed

+51
-13
lines changed

4 files changed

+51
-13
lines changed

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ RUN apk add jq
1111
# add curl for pull requests via github api
1212
RUN apk add curl
1313

14+
COPY errors-matcher.json /errors-matcher.json
1415
COPY entrypoint.sh /entrypoint.sh
1516

1617
RUN chmod 777 entrypoint.sh
1718

18-
ENTRYPOINT ["/entrypoint.sh"]
19+
ENTRYPOINT ["/entrypoint.sh"]

action.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,3 @@ inputs:
2222
runs:
2323
using: 'docker'
2424
image: 'Dockerfile'
25-
args:
26-
- ${{ inputs.REPOSITORIES }}
27-
- ${{ inputs.FILES }}
28-
- ${{ inputs.TOKEN }}
29-
- ${{ inputs.PULL_REQUEST }}

entrypoint.sh

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
#!/bin/bash
22

3+
STATUS=0
4+
5+
# remember last error code
6+
trap 'STATUS=$?' ERR
7+
8+
# problem matcher must exist in workspace
9+
cp /errors-matcher.json $HOME/file-sync-errors-matcher.json
10+
echo "::add-matcher::$HOME/file-sync-errors-matcher.json"
11+
312
echo "Repository: [$GITHUB_REPOSITORY]"
413

514
# log inputs
@@ -36,13 +45,13 @@ echo " "
3645

3746
# loop through all the repos
3847
for repository in "${REPOSITORIES[@]}"; do
39-
echo "###[group] $repository"
48+
echo "::group::$repository"
4049

4150
# determine repo name
4251
REPO_INFO=($(echo $repository | tr "@" "\n"))
4352
REPO_NAME=${REPO_INFO[0]}
4453
echo "Repository name: [$REPO_NAME]"
45-
54+
4655
# determine branch name
4756
BRANCH_NAME="master"
4857
if [ ${REPO_INFO[1]+yes} ]; then
@@ -65,15 +74,15 @@ for repository in "${REPOSITORIES[@]}"; do
6574
fi
6675

6776
echo " "
68-
77+
6978
# loop through all files
7079
for file in "${FILES[@]}"; do
7180
echo "File: [${file}]"
7281
# split and trim
7382
FILE_TO_SYNC=($(echo $file | tr "=" "\n"))
7483
SOURCE_PATH=${FILE_TO_SYNC[0]}
7584
echo "Source path: [$SOURCE_PATH]"
76-
85+
7786
# initialize the full path
7887
SOURCE_FULL_PATH="${GITHUB_WORKSPACE}/${SOURCE_PATH}"
7988
echo "Source full path: [$SOURCE_FULL_PATH]"
@@ -103,7 +112,7 @@ for repository in "${REPOSITORIES[@]}"; do
103112
# copy file
104113
echo "Copying: [$SOURCE_FULL_PATH] to [$DEST_FULL_PATH]"
105114
cp "${SOURCE_FULL_PATH}" "${DEST_FULL_PATH}" -r
106-
115+
107116
# add file
108117
git add "${DEST_FULL_PATH}" -f
109118

@@ -137,5 +146,7 @@ for repository in "${REPOSITORIES[@]}"; do
137146
cd $TEMP_PATH
138147
rm -rf $REPO_NAME
139148
echo "Completed [${REPO_NAME}]"
140-
echo "###[endgroup]"
141-
done
149+
echo "::endgroup::"
150+
done
151+
152+
exit $STATUS

errors-matcher.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"problemMatcher": [
3+
{
4+
"owner": "error1",
5+
"pattern": [
6+
{
7+
"regexp": "^(.*error: .*)$",
8+
"message": 1
9+
}
10+
]
11+
},
12+
{
13+
"owner": "error2",
14+
"pattern": [
15+
{
16+
"regexp": "^.*(\\[remote rejected\\] .*)$",
17+
"message": 1
18+
}
19+
]
20+
},
21+
{
22+
"owner": "error3",
23+
"pattern": [
24+
{
25+
"regexp": "^.*(cp: can't stat .*)$",
26+
"message": 1
27+
}
28+
]
29+
}
30+
]
31+
}

0 commit comments

Comments
 (0)