Skip to content

Commit a0bfbaf

Browse files
authored
feat(ci): use actions-diff-triggers (#25)
1 parent 9a3a8ba commit a0bfbaf

File tree

1 file changed

+24
-73
lines changed

1 file changed

+24
-73
lines changed

action.yml

Lines changed: 24 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,6 @@ inputs:
6060
runs:
6161
using: composite
6262
steps:
63-
- uses: actions/checkout@v4
64-
with:
65-
fetch-depth: 0
66-
repository: ${{ inputs.repository }}
67-
ref: ${{ inputs.branch }}
68-
6963
- name: Warnings for breaking changes
7064
shell: bash
7165
run: |
@@ -78,56 +72,18 @@ runs:
7872
exit 1
7973
fi
8074
81-
# Process variables and inputs
82-
- id: vars
83-
shell: bash
84-
run: |
85-
# Triggers and conditions
86-
87-
if [ "${{ inputs.java-cache }}" == "maven" ]; then
88-
echo sonarCmd="mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar" >> $GITHUB_OUTPUT
89-
elif [ "${{ inputs.java-cache }}" == "gradle" ]; then
90-
echo sonarCmd="./gradlew build sonarqube --info" >> $GITHUB_OUTPUT
91-
else
92-
echo "ERROR: inputs.java-cache = ${{ inputs.java-cache }}"
93-
exit 1
94-
fi
95-
96-
# Arrays must be stored first
97-
TRIGGERS=${{ inputs.triggers }}
98-
T_EVENTS=${{ inputs.triggers_event }}
99-
100-
# Default to triggered=true
101-
echo "triggered=true" >> $GITHUB_OUTPUT
102-
103-
# Run/trigger conditions
104-
if [[ ! "${T_EVENTS}" =~ "${{ github.event_name }}" ]]
105-
then
106-
# Event doesn't match on type, so fire
107-
echo "Event not matched, so always test"
108-
exit 0
109-
elif [ -z "${TRIGGERS}" ]
110-
then
111-
# Triggers omitted, so fire
112-
echo "Triggers omitted, so always test"
113-
exit 0
114-
else
115-
# Check triggers against a git diff
116-
echo "Processing triggers"
117-
git fetch origin "${{ inputs.diff_branch }}"
118-
while read -r check; do
119-
for t in "${TRIGGERS[@]}"; do
120-
if [[ "${check}" =~ "${t}" ]]; then
121-
echo -e "Triggered: ${t}\n --> ${check}"
122-
exit 0
123-
fi
124-
done
125-
done < <(git diff origin/"${{ inputs.diff_branch }}" --name-only)
126-
fi
75+
# Send triggers to diff action
76+
- id: diff
77+
uses: bcgov-nr/action-diff-triggers@v0.2.0
78+
with:
79+
triggers: ${{ inputs.triggers }}
80+
diff_branch: ${{ inputs.diff_branch }}
12781

128-
# Conditions not met, do not fire
129-
echo "Triggers not matched, testing skipped"
130-
echo "triggered=false" >> $GITHUB_OUTPUT
82+
- uses: actions/checkout@v4
83+
with:
84+
fetch-depth: 0
85+
repository: ${{ inputs.repository }}
86+
ref: ${{ inputs.branch }}
13187

13288
# Setup Java and cache dir
13389
- uses: actions/setup-java@v4
@@ -139,38 +95,33 @@ runs:
13995

14096
# Run tests, hopefully generating coverage for SonarCloud
14197
- name: Run Tests
142-
if: steps.vars.outputs.triggered == 'true'
98+
if: steps.diff.outputs.triggered == 'true'
14399
shell: bash
100+
working-directory: ${{ inputs.dir }}
144101
run: |
145102
# Run tests
146-
cd ${{ inputs.dir }}
147103
${{ inputs.commands }}
148104
149105
### Optional SonarCloud
150106

151-
- if: inputs.sonar_token && steps.vars.outputs.triggered == 'true'
107+
- if: inputs.sonar_token && steps.diff.outputs.triggered == 'true'
152108
env:
153109
SONAR_TOKEN: ${{ inputs.sonar_token }}
154110
shell: bash
111+
working-directory: ${{ inputs.dir }}
155112
run: |
156113
# Run SonarCloud for ${{ inputs.java-cache }}
157-
cd ${{ inputs.dir }}
158-
${{ steps.vars.outputs.sonarCmd }} \
159-
-Dsonar.host.url=https://sonarcloud.io ${{ inputs.sonar_args }}
160114
161-
### Cleanup
115+
if [ "${{ inputs.java-cache }}" == "maven" ]; then
116+
mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.host.url=https://sonarcloud.io ${{ inputs.sonar_args }}
117+
elif [ "${{ inputs.java-cache }}" == "gradle" ]; then
118+
gradlew build sonarqube --info -Dsonar.host.url=https://sonarcloud.io ${{ inputs.sonar_args }}
119+
else
120+
echo "ERROR: inputs.java-cache = ${{ inputs.java-cache }}"
121+
exit 1
122+
fi
162123
163-
# Fix - Docker can take file ownership, causing a cleanup fail
164-
- shell: bash
165-
if: steps.vars.outputs.triggered == 'true'
166-
id: get_uid
167-
run: |
168-
# User for workstation ownership reset/fix
169-
echo "uid=$(id -u ${USER})" >> $GITHUB_OUTPUT
170-
- uses: peter-murray/reset-workspace-ownership-action@v1
171-
if: steps.vars.outputs.triggered == 'true'
172-
with:
173-
user_id: ${{ steps.get_uid.outputs.uid }}
124+
### Cleanup
174125

175126
# Fix - Clone for action.yml and other verifications
176127
- name: Checkout Action repo to pass tests

0 commit comments

Comments
 (0)