mirror of
https://github.com/obi1kenobi/cargo-semver-checks-action.git
synced 2024-11-22 16:09:33 +01:00
Add test for baseline caching (#33)
* Cache test * Baseline caching - initial work * Add comment explaining the change of CARGO_TARGET_DIR. * Update README.md Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com> * Refactor getRustcVersion and getCargoSemverChecksVersion * Move helper functions outside RustdocCache class. * cachePath passed in constructor * workspaceRoot as constructor argument * Inline getManifestDir * Change target to semver-checks/target * Fix missing hash-files * Add workflow testing caching * New line * Add checking the updated cache * Missing semicolon * Bad job name in cache key * Upload cache if its hash changes * Test options cache-key and prefix-key * Need to use restore-keys * Is path a problem? * Absolute path * Move * Fix restore inputs * Verify * Revert debug * Rustc and semver-checks versions should not be fixed! * debug test * key not being a prefix * Missing outputs * Revert letter change in hash * Update CI README * TODO comments, shorter names * Better names * check the key * Missing ' * Remove space * Missing outputs * Remove hash check --------- Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com> * Remove inconsistent newlines from workflows README --------- Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>
This commit is contained in:
parent
a976a2e219
commit
461983b3bb
3 changed files with 75 additions and 7 deletions
16
.github/workflows/README.md
vendored
16
.github/workflows/README.md
vendored
|
@ -1,9 +1,11 @@
|
||||||
The testing workflow is divided into three parts:
|
The testing workflow is divided into several parts:
|
||||||
- `test-build.yml` is run on `ubuntu-latest` and contains source-related checks:
|
|
||||||
linters, formatters and verifying whether the sources match dist/ directory.
|
- `test-action.yml`, which contains simple, general integration tests of the action that should be run on each platform
|
||||||
- `test-action.yml` contains simple, general integration tests of the action
|
|
||||||
that should be run on each platform.
|
and the following ones run on `ubuntu-latest`:
|
||||||
- `test-inputs.yml` is run on `ubuntu-latest` and contains specific integration
|
|
||||||
tests checking whether the action inputs are processed properly.
|
- `test-build.yml` containing source-related checks: linters, formatters and verifying whether the sources match `dist/` directory,
|
||||||
|
- `test-inputs.yml` containing specific integration tests checking whether the action inputs are processed properly,
|
||||||
|
- `test-cache.yml` focusing on veryfing whether the baseline rustdoc is cached correctly.
|
||||||
|
|
||||||
`setup-test-workspace` is a helper action that creates a workspace containing two crates: the test fork of `ref_slice` and a dummy crate that has no matching baseline version on `crates.io`.
|
`setup-test-workspace` is a helper action that creates a workspace containing two crates: the test fork of `ref_slice` and a dummy crate that has no matching baseline version on `crates.io`.
|
||||||
|
|
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
|
@ -27,3 +27,7 @@ jobs:
|
||||||
test-inputs:
|
test-inputs:
|
||||||
name: Test action inputs
|
name: Test action inputs
|
||||||
uses: ./.github/workflows/test-inputs.yml
|
uses: ./.github/workflows/test-inputs.yml
|
||||||
|
|
||||||
|
test-cache:
|
||||||
|
name: Test rustdoc caching
|
||||||
|
uses: ./.github/workflows/test-cache.yml
|
||||||
|
|
62
.github/workflows/test-cache.yml
vendored
Normal file
62
.github/workflows/test-cache.yml
vendored
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
name: Test rustdoc caching
|
||||||
|
|
||||||
|
# Assumes that the latest published normal version of `ref_slice` smaller
|
||||||
|
# than 1.2.2 is 1.2.1.
|
||||||
|
# TODO: Change the crate version in the corresponding branches `patch_change`
|
||||||
|
# and `major_change` to 1.2.1 once new logic of choosing baseline is adapted.
|
||||||
|
# Otherwise if new version 1.2.2 of `ref_slice` is released, the tests might
|
||||||
|
# stop working correctly.
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_call:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test-cache-exists:
|
||||||
|
name: Check if the cache exists after running the action
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout the test repository and test with patch change and patch version bump
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
path: 'ref_slice'
|
||||||
|
repository: mgr0dzicki/cargo-semver-action-ref-slice
|
||||||
|
ref: patch_change
|
||||||
|
- name: Checkout the action
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
path: action
|
||||||
|
- name: Run the action
|
||||||
|
uses: ./action/
|
||||||
|
with:
|
||||||
|
manifest-path: 'ref_slice/Cargo.toml'
|
||||||
|
cache-key: testkey
|
||||||
|
prefix-key: testprefix
|
||||||
|
- name: Check if the cache directory exists
|
||||||
|
run: |
|
||||||
|
if ! grep -q "ref_slice-1.2.1/src/lib.rs" "semver-checks/target/semver-checks/cache/registry-ref_slice-1_2_1.json"; then
|
||||||
|
echo "Non-existent or invalid cache file!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
- name: Move the cache created by the action
|
||||||
|
run: |
|
||||||
|
mv semver-checks/target/semver-checks/cache action-cache
|
||||||
|
- name: Generate primary cache key
|
||||||
|
id: generate_key
|
||||||
|
run: |
|
||||||
|
RUSTC=$(rustc --version | sed -e 's/\s\+/-/g')
|
||||||
|
SEMVER_CHECKS=$(cargo semver-checks --version | sed -e 's/\s\+/-/g')
|
||||||
|
echo "KEY=testprefix-testkey-linux-$RUSTC-$SEMVER_CHECKS-da39a3ee5e6b4b0d3255bfef95601890afd80709-semver-checks-rustdoc" >> $GITHUB_OUTPUT
|
||||||
|
- name: Download saved cache
|
||||||
|
uses: actions/cache/restore@v3
|
||||||
|
with:
|
||||||
|
path: ${{ github.workspace }}/semver-checks/target/semver-checks/cache
|
||||||
|
fail-on-cache-miss: true
|
||||||
|
key: not_a_prefix
|
||||||
|
restore-keys: |
|
||||||
|
${{ steps.generate_key.outputs.KEY }}
|
||||||
|
- name: Compare local and downloaded cache files
|
||||||
|
run: |
|
||||||
|
if ! diff -r "semver-checks/target/semver-checks/cache" "action-cache"; then
|
||||||
|
echo "Downloaded cache does not match the local version!"
|
||||||
|
exit 1
|
||||||
|
fi
|
Loading…
Reference in a new issue