Skip to content

Commit

Permalink
checkout full repo history so diffing works
Browse files Browse the repository at this point in the history
  • Loading branch information
radhermit committed Nov 29, 2024
1 parent aace54d commit bb79946
Showing 3 changed files with 29 additions and 25 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ jobs:
- name: Checkout shared testdata
uses: actions/checkout@v4
with:
fetch-depth: 0
repository: pkgcraft/pkgcraft-testdata
path: testdata

5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -10,7 +10,8 @@ By default, the current working directory is used for a repo path.

## Example workflow

Note that the action requires using x86-64 Linux runners.
Note that for diffing to work, the full history of the target repo needs to be
fetched. Also, the action requires using x86-64 Linux runners.

```yaml
name: pkgcruft
@@ -25,6 +26,8 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Run pkgcruft
uses: pkgcraft/pkgcruft-action@main
```
48 changes: 24 additions & 24 deletions pkgcruft-action
Original file line number Diff line number Diff line change
@@ -7,27 +7,6 @@ set +e
(
set -e

# set up cache files
FILE=$(mktemp)
CACHE="${HOME}/.cache/pkgcruft/scans"
mkdir -p "${CACHE}"

# determine target commit
cd "${REPO}"
NEW_COMMIT=$(git rev-parse HEAD)
NEW_COMMIT_SHORT=$(git rev-parse --short HEAD)

# determine old commit for diff targeting
if [[ -n ${GIT_BASE_BRANCH} ]]; then
# pull request
OLD_COMMIT=$(git rev-parse ${GIT_BASE_BRANCH})
elif [[ ${GIT_BRANCH} != ${GIT_DEFAULT_BRANCH} ]]; then
# non-default branch
OLD_COMMIT=$(git rev-parse ${GIT_DEFAULT_BRANCH})
else
OLD_COMMIT=$(git rev-parse HEAD~1)
fi

# TODO: replace with native pkgcraft repo syncing functionality
# see https://github.com/pkgcraft/pkgcruft-action/issues/2
GENTOO_REPO="${HOME}/.cache/pkgcraft/repos/gentoo"
@@ -46,19 +25,40 @@ set +e
mkdir -p ~/.cache/pkgcruft/md5-cache metadata/md5-cache
sudo mount -o bind ~/.cache/pkgcruft/md5-cache metadata/md5-cache

# set up cache files
FILE=$(mktemp)
CACHE="${HOME}/.cache/pkgcruft/scans"
mkdir -p "${CACHE}"

# determine target commit
cd "${REPO}"
NEW_COMMIT=$(git rev-parse HEAD)
NEW_COMMIT_SHORT=$(git rev-parse --short HEAD)

echo Running pkgcruft: ${NEW_COMMIT}
pkgcruft scan -R json > "${FILE}"

echo Current pkgcruft results: ${NEW_COMMIT}
pkgcruft replay --color --sort "${FILE}"

# determine old commit for diff targeting
if [[ -n ${GIT_BASE_BRANCH} ]]; then
# pull request
OLD_COMMIT=$(git rev-parse ${GIT_BASE_BRANCH})
elif [[ ${GIT_BRANCH} != ${GIT_DEFAULT_BRANCH} ]]; then
# non-default branch
OLD_COMMIT=$(git rev-parse ${GIT_DEFAULT_BRANCH})
else
OLD_COMMIT=$(git rev-parse HEAD~1)
fi

# Generate results for old commit if they don't exist
if [[ ! -f ${CACHE}/${OLD_COMMIT} ]]; then
echo Running pkgcruft for diff targeting: ${OLD_COMMIT}
git checkout ${OLD_COMMIT}
pkgcruft scan -R json > "${CACHE}/${OLD_COMMIT}"
fi

echo Current pkgcruft results: ${NEW_COMMIT}
pkgcruft replay --color --sort "${FILE}"

# output diff if changes exists
diff=$(mktemp)
pkgcruft diff --color --sort "${CACHE}/${OLD_COMMIT}" "${FILE}" > "${diff}"

0 comments on commit bb79946

Please sign in to comment.