ramsey / composer-install

:gift: A GitHub Action to streamline installation of PHP dependencies with Composer.
MIT License
233 stars 32 forks source link

:sparkles: Add new `custom-cache-suffix` option #239

Closed jrfnl closed 2 years ago

jrfnl commented 2 years ago

Description

As discussed in #234.

This adds a new custom-cache-suffix option to the action which allows for adding a custom addition to the cache key, which can be helpful to break out of outdated caches, especially when a project does not have a committed composer.lock file.

Fixes #234

Motivation and context

See #234

How has this been tested?

Both unit tests as well as integration tests are included with the PR.

Types of changes

PR checklist

ramsey commented 2 years ago

Something about the cache_key_08.exp test is causing a failure, but I can't tell what it is yet.

jrfnl commented 2 years ago

Something about the cache_key_08.exp test is causing a failure, but I can't tell what it is yet.

Windows and file permissions. Should be fixed now.

jrfnl commented 2 years ago

Hmm.. Composer v1 still giving trouble...

jrfnl commented 2 years ago

(which is weird as I had a passing build before I tidied up and rebased)

jrfnl commented 2 years ago

@ramsey As by now it's not the new test which is failing, could you restart the build just to check it wasn't some Composer hick-up ?

ramsey commented 2 years ago

Re-running

codecov[bot] commented 2 years ago

Codecov Report

Merging #239 (6f57711) into v2 (7f9021e) will increase coverage by 0.02%. The diff coverage is 100.00%.

Additional details and impacted files [![Impacted file tree graph](https://codecov.io/gh/ramsey/composer-install/pull/239/graphs/tree.svg?width=650&height=150&src=pr&token=ZP54XdHMGI&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Ben+Ramsey)](https://codecov.io/gh/ramsey/composer-install/pull/239?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Ben+Ramsey) ```diff @@ Coverage Diff @@ ## v2 #239 +/- ## ========================================== + Coverage 97.45% 97.47% +0.02% ========================================== Files 5 5 Lines 118 119 +1 ========================================== + Hits 115 116 +1 Misses 3 3 ``` | [Impacted Files](https://codecov.io/gh/ramsey/composer-install/pull/239?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Ben+Ramsey) | Coverage Δ | | |---|---|---| | [bin/cache\_key.sh](https://codecov.io/gh/ramsey/composer-install/pull/239/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Ben+Ramsey#diff-YmluL2NhY2hlX2tleS5zaA==) | `95.00% <100.00%> (+0.12%)` | :arrow_up: |
jrfnl commented 2 years ago

Right first round done: applied this in some 40 repos ;-)

For anyone looking for some more date-based example code:

      - name: Install Composer dependencies
        uses: ramsey/composer-install@v2
        with:
          # Bust the cache at least once every three months - output format: YYYYqQ, example: 2022q4.
          custom-cache-suffix: $(/bin/date +%Y)q$(( ($(/bin/date +%-m)-1)/3+1 ))

      - name: Install Composer dependencies
        uses: ramsey/composer-install@v2
        with:
          # Bust the cache at least once a month - output format: YYYY-MM-DD.
          custom-cache-suffix: $(date -u -d "-0 month -$(($(date +%d)-1)) days" "+%F")

      - name: Install Composer dependencies
        uses: ramsey/composer-install@v2
        with:
          # Bust the cache at least once a week - output format: YYYY-MM-DD.
          custom-cache-suffix: $(/bin/date -u --date='last Mon' "+%F")
jrfnl commented 1 year ago

Simplified version of the "once a month" code sample:

      - name: Install Composer dependencies
        uses: ramsey/composer-install@v2
        with:
          # Bust the cache at least once a month - output format: YYYY-MM.
          custom-cache-suffix: $(date -u "+%Y-%m")