Skip to content

Commit 4df7e78

Browse files
committed
feat: improve comment drafter
1 parent 1731f6c commit 4df7e78

File tree

2 files changed

+451
-162
lines changed

2 files changed

+451
-162
lines changed

action.yml

Lines changed: 69 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,34 @@ runs:
5252
# ----------------------------------------
5353
# 'create-comment' step
5454
# ----------------------------------------
55+
- name: Checkout main repo
56+
if: ${{ inputs.step == 'create-comment' }}
57+
uses: actions/checkout@v4
58+
with:
59+
fetch-depth: 0
60+
61+
- name: Get variables from repo
62+
if: ${{ inputs.step == 'create-comment' }}
63+
id: env-variables-repo
64+
run: |
65+
# snakemake config prefix
66+
config_prefix=$(yq eval '.run.prefix' ${{ inputs.snakemake_config }})
67+
echo "Config prefix: ${config_prefix}"
68+
echo "config_prefix=${config_prefix}" >> $GITHUB_OUTPUT
69+
70+
# git diff config
71+
rm -f ~/git_diff_config.txt
72+
git_diff_config=$(git diff origin/${{ github.base_ref }}..origin/${{ github.head_ref }} -- ${{ inputs.snakemake_config }})
73+
echo "Git diff config: ${git_diff_config}"
74+
echo "git_diff_config=${git_diff_config}" >> ~/git_diff_config.txt
75+
76+
# Assert variables found
77+
if [[ -z $config_prefix ]]; then
78+
echo "Error: Config prefix not found"
79+
exit 1
80+
fi
81+
shell: bash
82+
5583
- name: Checkout plot repo
5684
if: ${{ inputs.step == 'create-comment' }}
5785
uses: actions/checkout@v4
@@ -63,38 +91,57 @@ runs:
6391
- name: Download artifacts
6492
if: ${{ inputs.step == 'create-comment' }}
6593
uses: actions/download-artifact@v4
94+
95+
- name: Get variables from artifacts
96+
if: ${{ inputs.step == 'create-comment' }}
97+
id: env-variables-artifacts
98+
run: |
99+
# Get compared hashes
100+
hash_base=$(yq e '.metadata.hash_base' validator-metadata/validator-metadata.yml)
101+
feature_commit_hash=$(yq e '.metadata.feature_commit_hash' validator-metadata/validator-metadata.yml)
102+
103+
# Assert variables found
104+
if [[ -z $hash_base || -z $feature_commit_hash ]]; then
105+
echo "Error: Commit hashes not found"
106+
exit 1
107+
fi
108+
109+
# Print and save variables
110+
echo "Main commit hash: ${hash_base}"
111+
echo "Feature commit hash: ${feature_commit_hash}"
112+
echo "hash_base=${hash_base}" >> $GITHUB_OUTPUT
113+
echo "hash_feature=${feature_commit_hash}" >> $GITHUB_OUTPUT
114+
115+
shell: bash
66116

67117
- name: Upload relevant plots
118+
id: upload-plots
68119
if: ${{ inputs.step == 'create-comment' }}
69120
run: |
70121
rm -rf _validation-images
71122
mkdir -p _validation-images/feature
72123
mkdir -p _validation-images/base
73-
74-
echo "Plots: ${{ inputs.plots }}"
75-
76-
# Copy plots
124+
125+
# Copy plots
77126
read -a plots_array <<< ${{ inputs.plots }}
78127
echo "Plots: ${plots_array[@]}"
79-
80128
for plot in "${plots_array[@]}"
81129
do
82130
echo "Copying ${plot}"
83-
cp -r "results (feature branch)${plot}" "_validation-images/feature"
84-
cp -r "results (base branch)${plot}" "_validation-images/base"
131+
cp -r "results (feature branch)/${{ steps.env-variables-repo.outputs.config_prefix }}/${plot}" "_validation-images/feature"
132+
cp -r "results (base branch)/${{ steps.env-variables-repo.outputs.config_prefix }}/${plot}" "_validation-images/base"
85133
done
86134
87-
ls -R _validation-images
88-
89135
# Bot config
90136
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
91137
git config --global user.name "github-actions[bot]"
92138
93139
# Add plots to repo branch
140+
echo "Adding plots to repo branch"
94141
git add _validation-images
95142
git commit -m "[github-actions.ci] upload validation images to show in comment" || true # ignore if no changes
96143
git push origin ${{ github.event.repository.name }}
97-
echo "COMMIT_ID=$(git rev-parse HEAD)" >> $GITHUB_ENV
144+
echo "COMMIT_ID=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
98145
shell: bash
99146

100147
- name: Draft comment
@@ -104,28 +151,23 @@ runs:
104151
git fetch origin
105152
git merge origin/main --allow-unrelated-histories
106153
107-
# Get plot files
108-
for file in _validation-images/base/*; do
109-
[ -e "$file" ] || continue
110-
plot_files+=( "$(basename "$file")" )
111-
done
112-
113-
# Read in validator-metadata.yml
114-
main_commit_hash=$(yq e '.metadata.main_commit_hash' validator-metadata/validator-metadata.yml)
115-
feature_commit_hash=$(yq e '.metadata.feature_commit_hash' validator-metadata/validator-metadata.yml)
154+
git_diff_config=$(cat ~/git_diff_config.txt)
155+
export GIT_DIFF_CONFIG=$(cat ~/git_diff_config.txt)
116156
157+
echo "${{ inputs.plots }}"
117158
pip install -r requirements.txt
118159
python draft_comment.py \
119160
--repo ${{ github.repository }} \
161+
--artifact_url "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
162+
--branch_name_base ${{ github.base_ref }} \
163+
--branch_name_feature ${{ github.head_ref }} \
164+
--hash_base "${{ steps.env-variables-artifacts.outputs.hash_base }}" \
165+
--hash_feature "${{ steps.env-variables-artifacts.outputs.hash_feature }}" \
166+
--config_prefix "${{ steps.env-variables-repo.outputs.config_prefix }}" \
120167
--dir_base "results (base branch)" \
121168
--dir_feature "results (feature branch)" \
122-
--plots_commit_id ${{ env.COMMIT_ID }} \
123-
--plots "${plot_files[@]}" \
124-
--artifact_url "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
125-
--feature_branch_name ${{ github.head_ref }} \
126-
--base_branch_name ${{ github.base_ref }} \
127-
--feature_commit $feature_commit_hash \
128-
--base_commit $main_commit_hash \
169+
--plots_hash ${{ steps.upload-plots.outputs.COMMIT_ID }} \
170+
--plots "${{ inputs.plots }}" \
129171
> comment.txt
130172
shell: bash
131173

@@ -167,7 +209,7 @@ runs:
167209
owner,
168210
repo,
169211
issue_number,
170-
body: `Initial message`
212+
body: `<!-- ${distinctiveKeyword} --> Initializing comment...`
171213
});
172214
173215
return newComment.id;

0 commit comments

Comments
 (0)