Skip to content

[Diff] using pull_request_target #1053

[Diff] using pull_request_target

[Diff] using pull_request_target #1053

name: πŸ‘€ Detect public API changes
on:
pull_request_target:
types: [opened, synchronize, reopened, labeled, unlabeled, edited]
pull_request:
types: [opened, synchronize, reopened, labeled, unlabeled, edited]
workflow_dispatch:
inputs:
new:
description: 'Branch/tag of the new/updated version'
required: true
old:
description: 'Branch/tag of the old/comparison version'
required: true
permissions:
pull-requests: write
issues: write
jobs:
build:
runs-on: macos-14
steps:
- uses: actions/checkout@v4
- name: Select latest Xcode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: '16.1'
- name: 🚚 Fetch repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- if: ${{ github.event.pull_request.base.ref != '' }}
name: Test Comment PR
uses: thollander/actions-comment-pull-request@v2
with:
message: "Hello World"
comment_tag: test_comment
- name: πŸ‘Ύ Define Diff Versions
run: |
NEW="${{ env.source }}~${{ env.headGithubRepo }}"
OLD="${{ env.target }}~${{ env.baseGithubRepo }}"
# Release branches get compared to the last tag instead of the target branch
if [[ '${{ github.head_ref || env.noTargetBranch }}' == release/* ]]
then
LATEST_TAG=$(git describe --tags --abbrev=0)
OLD="$LATEST_TAG~${{ env.baseGithubRepo }}"
fi
# Providing the output to the environment
echo "OLD_VERSION=$OLD" >> $GITHUB_ENV
echo "NEW_VERSION=$NEW" >> $GITHUB_ENV
env:
source: '${{ github.event.inputs.new || github.head_ref }}'
target: '${{ github.event.inputs.old || github.event.pull_request.base.ref }}'
headGithubRepo: '${{github.server_url}}/${{ github.event.pull_request.head.repo.full_name || github.repository}}.git'
baseGithubRepo: '${{github.server_url}}/${{github.repository}}.git'
noTargetBranch: 'no target branch'
- uses: actions/checkout@v4
with:
repository: "Adyen/adyen-swift-public-api-diff"
ref: "0.7.0"
path: "public-api-diff"
- name: πŸ‘Ύ Compute binary path
run: |
cd $GITHUB_WORKSPACE/public-api-diff
echo "BINARY_PATH=$(swift build --configuration release --show-bin-path)/public-api-diff" >> $GITHUB_ENV
- name: πŸ›» Restore Binary
id: cache-restore
uses: actions/cache/restore@v3
with:
path: ${{ env.BINARY_PATH }}
key: build-cache-${{ runner.os }}-0.7.0
- name: 🧰 Build Swift CLI
if: steps.cache-restore.outputs.cache-hit != 'true'
run: |
cd $GITHUB_WORKSPACE/public-api-diff
swift build --configuration release
- name: πŸͺͺ Verify binary exists
run: |
if [ ! -f ${{ env.BINARY_PATH }} ]; then
echo "Binary not found at ${{ env.BINARY_PATH }} after build"
exit 1
else
echo "Binary found at ${{ env.BINARY_PATH }}"
fi
- name: πŸ’Ύ Save Binary
if: steps.cache-restore.outputs.cache-hit != 'true'
uses: actions/cache/save@v3
with:
path: ${{ env.BINARY_PATH }}
key: build-cache-${{ runner.os }}-0.7.0
- name: "πŸƒ Run Diff"
run: |
NEW=${{ env.NEW_VERSION }}
OLD=${{ env.OLD_VERSION }}
PLATFORM=${{ env.platform }}
BINARY_PATH=${{ env.BINARY_PATH }}
PROJECT_FOLDER=$PWD
echo $PROJECT_FOLDER
$BINARY_PATH project --new "$NEW" --old "$OLD" --platform "$PLATFORM" --output "$PROJECT_FOLDER/api_comparison.md" --log-output "$PROJECT_FOLDER/logs.txt"
cat "$PROJECT_FOLDER/logs.txt"
cat "$PROJECT_FOLDER/api_comparison.md" >> $GITHUB_STEP_SUMMARY
env:
platform: "iOS"
- if: ${{ github.event.pull_request.base.ref != '' }}
name: πŸ“ Comment on PR
uses: thollander/actions-comment-pull-request@v3
with:
file-path: "${{ github.workspace }}/api_comparison.md"
comment-tag: api_changes
mode: recreate