@@ -10,34 +10,83 @@ inputs:
1010 old :
1111 description : ' Specify the old version to compare to'
1212 required : true
13+
1314runs :
1415 using : ' composite'
1516 steps :
17+ - name : 🍱 Compute prerequisites
18+ run : |
19+ echo "VERSION_NUMBER=0.7.0" >> $GITHUB_ENV
20+ echo "BINARY_PATH=$(swift build --configuration release --show-bin-path)/public-api-diff" >> $GITHUB_ENV
21+ echo "HEAD_GITHUB_REPO=${{github.server_url}}/${{ github.event.pull_request.head.repo.full_name || github.repository}}.git" >> $GITHUB_ENV
22+ echo "BASE_GITHUB_REPO=${{github.server_url}}/${{github.repository}}.git" >> $GITHUB_ENV
23+ shell : bash
24+
1625 - uses : actions/checkout@v4
1726 with :
1827 repository : " Adyen/adyen-swift-public-api-diff"
19- ref : " 0.7.0"
20- - name : " Run Diff"
28+ # ref: ${{ env.VERSION_NUMBER }}
29+
30+ - name : 🛻 Restore Binary
31+ id : cache-restore
32+ uses : actions/cache/restore@v3
33+ with :
34+ path : ${{ env.BINARY_PATH }}
35+ key : build-cache-${{ runner.os }}-${{ env.VERSION_NUMBER }}
36+
37+ - name : 🧰 Build Swift CLI
38+ if : steps.cache-restore.outputs.cache-hit != 'true'
39+ run : swift build --configuration release
40+ shell : bash
41+
42+ - name : 🪪 Verify binary exists
43+ run : |
44+ if [ ! -f ${{ env.BINARY_PATH }} ]; then
45+ echo "Binary not found at ${{ env.BINARY_PATH }} after build"
46+ exit 1
47+ else
48+ echo "Binary found at ${{ env.BINARY_PATH }}"
49+ fi
50+ shell : bash
51+
52+ - name : 💾 Save Binary
53+ if : steps.cache-restore.outputs.cache-hit != 'true'
54+ uses : actions/cache/save@v3
55+ with :
56+ path : ${{ env.BINARY_PATH }}
57+ key : build-cache-${{ runner.os }}-${{ env.VERSION_NUMBER }}
58+
59+ - name : 🏃 Run Diff
2160 run : |
2261 NEW=${{ inputs.new }}
2362 OLD=${{ inputs.old }}
2463 PLATFORM=${{ inputs.platform }}
64+ BINARY_PATH=${{ env.BINARY_PATH }}
2565 PROJECT_FOLDER=$PWD
26- echo $PROJECT_FOLDER
2766
28- swift run public-api-diff project --new "$NEW" --old "$OLD" --platform "$PLATFORM" --output "$PROJECT_FOLDER/api_comparison.md" --log-output "$PROJECT_FOLDER/logs.txt"
29- cat "$PROJECT_FOLDER/logs.txt"
67+ echo "▶️ Running binary at $BINARY_PATH"
68+ $BINARY_PATH project --new "$NEW" --old "$OLD" --platform "$PLATFORM" --output "$PROJECT_FOLDER/api_comparison.md" --log-output "$PROJECT_FOLDER/logs.txt"
69+ # cat "$PROJECT_FOLDER/logs.txt"
70+
71+ # if [[ ${{ env.HEAD_GITHUB_REPO != env.BASE_GITHUB_REPO }} ]]; then
72+ echo "---" >> $GITHUB_STEP_SUMMARY
73+ echo "> [!IMPORTANT]" >> $GITHUB_STEP_SUMMARY
74+ echo "> This PR is from a forked repository" >> $GITHUB_STEP_SUMMARY
75+ echo "> **Commenting on pull requests from forks is not possible** due to insufficient permissions." >> $GITHUB_STEP_SUMMARY
76+ echo "> Once merged, the output will be posted as an auto-updating comment under the pull request." >> $GITHUB_STEP_SUMMARY
77+ echo "---" >> $GITHUB_STEP_SUMMARY
78+ # fi
3079
3180 cat "$PROJECT_FOLDER/api_comparison.md" >> $GITHUB_STEP_SUMMARY
3281 shell : bash
33-
34- - if : ${{ github.event.pull_request.base.ref != '' }}
82+
83+ # We only want to comment if we're in a Pull Request and if the Pull Request is not from a forked Repository
84+ # Forked Repositories have different rights for security reasons and thus it's not possible to comment on PRs without lowering the security
85+ # once the tool is merged the base repo rights apply and the script can comment on PRs as expected.
86+ - if : ${{ github.event.pull_request.base.ref != '' && env.HEAD_GITHUB_REPO == env.BASE_GITHUB_REPO }}
3587 name : 📝 Comment on PR
3688 uses : thollander/actions-comment-pull-request@v3
3789 with :
3890 file-path : " ${{ github.workspace }}/api_comparison.md"
3991 comment-tag : api_changes
4092 mode : recreate
41-
42-
43-
0 commit comments