Skip to content

Commit a6ffcbf

Browse files
committed
chore: add diff
1 parent 822a7b3 commit a6ffcbf

File tree

1 file changed

+94
-21
lines changed

1 file changed

+94
-21
lines changed

.github/workflows/comment-diffs.yml

Lines changed: 94 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ jobs:
1717
- name: Checkout
1818
uses: actions/checkout@v3
1919

20+
- name: Copy config matrix to persist it
21+
run: |
22+
mkdir ../configMatrix
23+
cp ./.github/workflows/configMatrix.sh ../configMatrix/
24+
2025
- name: Setup
2126
uses: ./.github/actions/setup
2227

@@ -27,7 +32,7 @@ jobs:
2732
- name: Create old version libraries
2833
run: |
2934
# Source all the configuration values to load $languages, $types, and $exclude
30-
source ./.github/workflows/configMatrix.sh
35+
source ../configMatrix/configMatrix.sh
3136
3237
create_library() {
3338
library_type=$1
@@ -49,6 +54,9 @@ jobs:
4954
--no-example \
5055
--no-local \
5156
--react-native-version 0.73.0-rc.2
57+
58+
# Remove the .git folder of the created library
59+
rm -rf "$target_path/.git"
5260
}
5361
5462
for library_type in "${libraryTypes[@]}"; do
@@ -58,12 +66,6 @@ jobs:
5866
fi
5967
done
6068
done
61-
62-
- name: Fetch main
63-
run: git fetch origin main
64-
65-
- name: Checkout main
66-
run: git checkout origin/main
6769
6870
# - name: Setup again # Add a check here to setup again if deps changed
6971
# uses: ./.github/actions/setup
@@ -76,7 +78,10 @@ jobs:
7678
- name: Create library again
7779
run: |
7880
# Source all the configuration values to load $languages, $types, and $exclude
79-
source ./.github/workflows/configMatrix.sh
81+
source ../configMatrix/configMatrix.sh
82+
83+
git fetch origin main
84+
git checkout origin/main
8085
8186
create_library() {
8287
library_type=$1
@@ -98,6 +103,9 @@ jobs:
98103
--no-example \
99104
--no-local \
100105
--react-native-version 0.73.0-rc.2
106+
107+
# Remove the .git folder of the created library
108+
rm -rf "$target_path/.git"
101109
}
102110
103111
for library_type in "${libraryTypes[@]}"; do
@@ -108,20 +116,9 @@ jobs:
108116
done
109117
done
110118
111-
cd ..
112-
echo "$PWD"
113-
114-
# - uses: webfactory/[email protected]
115-
# with:
116-
# ssh-private-key: ${{ secrets.SSH_DEPLOY_KEY }}
117-
118-
- name: Create the Differ repo
119+
- name: Switch to diffs branch
119120
run: |
120-
mkdir differ
121-
cd differ
122-
git init
123-
git remote add origin ${{ vars.DIFF_VIEW_SSH }}
124-
desired_branch="${{ env.NEW_VERSION_BRANCH }}"
121+
desired_branch="diffs"
125122
# Check if the branch exists on the remote repository
126123
if git ls-remote --heads origin "$desired_branch" | grep -q "$desired_branch"; then
127124
echo "The branch $desired_branch already exists on the remote repository."
@@ -132,6 +129,82 @@ jobs:
132129
git checkout -b "$desired_branch" # Create a new branch and switch to it
133130
fi
134131
132+
- name: Initiate diffs
133+
run: |
134+
# Source all the configuration values to load $languages, $types, and $exclude
135+
source ../configMatrix/configMatrix.sh
136+
137+
output_path="../output"
138+
output_file="$output_path/output.txt"
139+
140+
mkdir -p "$output_path"
141+
142+
function copy_commit_diff(){
143+
library_type=$1
144+
language=$2
145+
146+
path_prefix="../test/$library_type/$language"
147+
target_path_new_version="$path_prefix/new-version"
148+
target_path_old_version="$path_prefix/old-version"
149+
150+
# Remove everything except the .git folder
151+
for i in $(ls | grep -v ".git") ; do rm -rf "$i"; done;
152+
153+
# Copy the old version
154+
cp -r "$target_path_old_version/." .
155+
156+
git config --global user.email "[email protected]"
157+
git config --global user.name "Github actions test"
158+
159+
# Add all files and commit
160+
git add -A || true && git commit -m "Automatic commit" || true
161+
162+
# Remove everything except the .git folder
163+
for i in $(ls | grep -v ".git") ; do rm -rf "$i"; done;
164+
165+
# Copy the new version
166+
cp -r "$target_path_new_version/." .
167+
168+
# Add all files and commit
169+
git add -A || true && git commit -m "Automatic commit" || true
170+
171+
# echo diff
172+
echo $(git diff HEAD~)
173+
174+
# Check if there is a diff
175+
if git diff --quiet HEAD~; then
176+
echo "No diff"
177+
else
178+
# Push the branches
179+
git push --set-upstream origin diffs
180+
181+
# Get new version remote commit hash
182+
new_version_commit_hash=$(git rev-parse --short origin/diffs)
183+
184+
# Get old version remote commit hash
185+
old_version_commit_hash=$(git rev-parse --short origin/diffs~)
186+
187+
# Add output to file
188+
echo "[$library_type/$language](https://github.com/${{github.repository}}/compare/$old_version_commit_hash..$new_version_commit_hash)" >> "$output_file"
189+
190+
# Add empty line
191+
echo \ >> $output_file
192+
fi
193+
}
194+
195+
for library_type in "${libraryTypes[@]}"; do
196+
for language in "${languages[@]}"; do
197+
if [[ ! "${exclude[*]}" =~ ${library_type}/${language} ]]; then
198+
copy_commit_diff "$library_type" "$language"
199+
fi
200+
done
201+
done
202+
203+
204+
# - uses: webfactory/[email protected]
205+
# with:
206+
# ssh-private-key: ${{ secrets.SSH_DEPLOY_KEY }}
207+
135208
- name: Clean the Differ repo
136209
run: |
137210
cd differ

0 commit comments

Comments
 (0)