Skip to content

Commit bca359d

Browse files
committed
Create separate workflow for PRs
1 parent 265a345 commit bca359d

2 files changed

Lines changed: 44 additions & 15 deletions

File tree

github-action-build.sh

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,30 +75,20 @@ EOL
7575
# Determine whether deploying will be possible.
7676
deployOK=
7777
ciURL=$(mvn -q -Denforcer.skip=true -Dexec.executable=echo -Dexec.args='${project.ciManagement.url}' --non-recursive validate exec:exec 2>&1)
78+
7879
if [ $? -ne 0 ]; then
7980
echo "No deploy -- could not extract ciManagement URL"
8081
echo "Output of failed attempt follows:"
8182
echo "$ciURL"
8283
else
83-
ciRepo=${ciURL##*/}
84-
ciPrefix=${ciURL%/*}
85-
ciOrg=${ciPrefix##*/}
86-
git config --get remote.origin.url
87-
curl -o pull-request.txt https://api.github.com/repos/$ciOrg/$ciRepo/pulls >/dev/null 2>&1 # Check for pull requests
88-
curl -o secure-env.txt https://api.github.com/orgs/$ciOrg/$ciRepo/secrets >/dev/null 2>&1 # Check for secure env var
89-
if ! grep -q "documentation_url" secure-env.txt; then
84+
if [ ! $GPG_KEY_NAME ] || [ ! $GPG_PASSPHRASE ] || [ ! $MAVEN_PASS ] || [ ! $OSSRH_PASS ]; then
9085
echo "No deploy -- secure environment variables not available"
91-
elif grep -q "url" pull-request.txt; then
86+
elif [ $FROM_PR ]; then
9287
echo "No deploy -- pull request detected"
93-
elif [ ${repo_fork} != "$ciOrg/$ciRepo" ]; then
94-
echo "No deploy -- repository fork: ${repo_fork} != $ciOrg/$ciRepo"
9588
else
9689
echo "All checks passed for artifact deployment"
9790
deployOK=1
9891
fi
99-
# Delete created txt file
100-
rm pull-request.txt
101-
rm secure-env.txt
10292
fi
10393

10494
# Install GPG on OSX/macOS

github-actionify.sh

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ dir="$(dirname "$0")"
1616
gitactionDir=.github
1717
gitactionConfigRoot=/workflows/.gitaction.yml
1818
gitactionConfig=$gitactionDir$gitactionConfigRoot
19+
gitactionPRConfig=$gitactionDir/workflows/.gitaction-pr.yml
1920
gitactionBuildScript=$gitactionDir/build.sh
2021
gitactionSettingsFile=$gitactionDir/settings.xml
2122
gitactionNotifyScript=$gitactionDir/notify.sh
@@ -116,19 +117,55 @@ process() {
116117

117118
test -e "$gitactionDir" -a ! -d "$gitactionDir" && die "$gitactionDir is not a directory"
118119
test -e "$gitactionConfig" -a ! -f "$gitactionConfig" && die "$gitactionConfig is not a regular file"
120+
test -e "$gitactionPRConfig" -a ! -f "$gitactionPRConfig" && die "$gitactionPRConfig is not a regular file"
119121
test -e "$gitactionConfig" && warn "$gitactionConfig already exists"
120122
test -e "$gitactionBuildScript" && warn "$gitactionBuildScript already exists"
121123

122124
# -- Do things --
123125

124-
# Add/update the GitHun Actions configuration file.
126+
# Add/update the main GitHun Actions configuration file.
125127
cat >"$tmpFile" <<EOL
126128
name: SciJava CI
127129
128130
on:
129131
push:
130132
branches:
131133
- $defaultBranch
134+
135+
jobs:
136+
build:
137+
runs-on: ubuntu-latest
138+
139+
steps:
140+
- uses: actions/checkout@v2
141+
142+
- name: Cache m2 modules
143+
uses: actions/cache@v2
144+
env:
145+
cache-name: cache-node-modules
146+
with:
147+
path: ~/.m2
148+
key: \${{ runner.os }}-build-\${{ env.cache-name }}
149+
restore-keys: |
150+
\${{ runner.os }}-build-\${{ env.cache-name }}-
151+
\${{ runner.os }}-build-
152+
\${{ runner.os }}-
153+
154+
- name: Set up JDK 8
155+
uses: actions/setup-java@v2
156+
with:
157+
java-version: '8'
158+
distribution: 'zulu'
159+
- name: Build with Maven
160+
run: ./$gitactionBuildScript
161+
EOL
162+
update "$gitactionConfig"
163+
164+
# Add/update the GitHun Actions PR configuration file.
165+
cat >"$tmpFile" <<EOL
166+
name: SciJava PR CI
167+
168+
on:
132169
pull_request:
133170
branches:
134171
- $defaultBranch
@@ -159,8 +196,10 @@ jobs:
159196
distribution: 'zulu'
160197
- name: Build with Maven
161198
run: ./$gitactionBuildScript
199+
env:
200+
FROM_PR: true
162201
EOL
163-
update "$gitactionConfig"
202+
update "$gitactionPRConfig"
164203

165204
# Add/update the GitHub Action build script.
166205
cat >"$tmpFile" <<EOL

0 commit comments

Comments
 (0)