Skip to content

Commit a6f6770

Browse files
authored
fixes #1: add branch input and changed-branch output to see remote branch diff (#2)
* change script type * update control flow to output more information
1 parent 7406f74 commit a6f6770

3 files changed

Lines changed: 38 additions & 5 deletions

File tree

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,20 @@ URL from which to fetch Nimbus experiments. Default: `https://experimenter.servi
2020

2121
**Required** App name by which to filter experiments. Example: `fenix`
2222

23+
### `branch`
24+
25+
**Required** Remote branch to check diff against. Example: `automation/update-nimbus-experiments`
26+
2327
## Outputs
2428

2529
### `changed`
2630

2731
The number of files that were modified as part of the script.
2832

33+
### `changed-branch`
34+
35+
The number of files that were modified as compared to the supplied remote branch.
36+
2937
## Example usage
3038

3139
```yaml
@@ -34,4 +42,5 @@ with:
3442
repo-path: main
3543
output-path: app/src/main/res/raw/initial_experiments.json
3644
experimenter-url: https://experimenter.services.mozilla.com/api/v6/experiments/
45+
branch: automation/update-nimbus-experiments
3746
```

action.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,20 @@ inputs:
1414
app-name:
1515
description: 'App name by which to filter experiments'
1616
required: true
17+
branch:
18+
description: 'Remote branch to check diff against'
19+
required: true
1720
outputs:
1821
changed:
1922
description: 'The number of files that were modified as part of the script'
23+
changed-branch:
24+
description: 'The number of files that were modified as compared to the supplied remote branch'
2025
runs:
2126
using: 'docker'
2227
image: 'Dockerfile'
2328
args:
2429
- ${{ inputs.repo-path }}
2530
- ${{ inputs.output-path }}
2631
- ${{ inputs.experimenter-url }}
27-
- ${{ inputs.app-name }}
32+
- ${{ inputs.app-name }}
33+
- ${{ inputs.branch }}

entrypoint.sh

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh -l
1+
#!/bin/bash
22

33
git config --global --add safe.directory "/github/workspace/$1"
44

@@ -7,12 +7,30 @@ curl $3 | jq --arg APP_NAME "$4" '{"data":map(select(.appName == $APP_NAME))}' >
77

88
git status
99
export CHANGED=$(git status -s | wc -l)
10+
export CHANGED_BRANCH=0
1011

1112
if test $CHANGED -eq 1
1213
then
13-
git add $2
14-
echo "$CHANGED file(s) have been modified"
14+
git add $2
15+
echo "$CHANGED file(s) have been modified"
16+
17+
export REMOTE_BRANCH=$(git ls-remote --head origin $5)
18+
if [[ -z $REMOTE_BRANCH ]];
19+
then
20+
export CHANGED_BRANCH=1
21+
echo "Remote branch currently does not exist; outputting that there are changes."
22+
else
23+
export CHANGED_BRANCH=$(git --no-pager diff origin/$5 | grep $2 | wc -l)
24+
if test $CHANGED_BRANCH -eq 1
25+
then
26+
echo "Remote branch differs from current changes, it should be updated."
27+
else
28+
echo "Remote branch and current changes are equivalent."
29+
fi
30+
fi
1531
else
16-
echo "No changes to make, exiting job"
32+
echo "No changes to make, exiting job"
1733
fi
34+
1835
echo "::set-output name=changed::$CHANGED"
36+
echo "::set-output name=changed-branch::$CHANGED_BRANCH"

0 commit comments

Comments
 (0)