Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/keinos/gh-action-hash-for-cache
GitHub Action of enhanced hashFiles for all runners (Windows, macOS and Linux.)
https://github.com/keinos/gh-action-hash-for-cache
actions github-action github-actions hashfile
Last synced: 18 days ago
JSON representation
GitHub Action of enhanced hashFiles for all runners (Windows, macOS and Linux.)
- Host: GitHub
- URL: https://github.com/keinos/gh-action-hash-for-cache
- Owner: KEINOS
- Created: 2022-01-21T03:08:14.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-09-10T07:01:14.000Z (about 1 year ago)
- Last Synced: 2024-10-14T03:40:56.726Z (about 1 month ago)
- Topics: actions, github-action, github-actions, hashfile
- Homepage:
- Size: 24.4 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[![Test](https://github.com/KEINOS/gh-action-hash-for-cache/actions/workflows/basic_func_test.yml/badge.svg)](https://github.com/KEINOS/gh-action-hash-for-cache/actions/workflows/basic_func_test.yml)
[![linux-mac-win](https://github.com/KEINOS/gh-action-hash-for-cache/actions/workflows/platform_test.yml/badge.svg)](https://github.com/KEINOS/gh-action-hash-for-cache/actions/workflows/platform_test.yml)# Unique Key (file hash) Generator for Caching
This GitHub Action generates a unique key (file hash) from one or more files for caching.
It **works on Linux, macOS, and Windows runners**.
```yaml
- uses: KEINOS/gh-action-hash-for-cache@main
id:
with:
path: |
variant:
```- `path`: A list of files that will be hashed.
- `variant`: A string to be hashed. (Optional)
- Exposed variable: `hash`
- To obtain the hash value: `steps..outputs.hash`
- Detailed examples follows.## About
[This GitHub Action](https://github.com/KEINOS/gh-action-hash-for-cache):
- **Simply generates a hash of the given entry**.
- If the content of the entry is changed, a different hash will be obtained.
- Useful to generate a unique key or ID for caching.
- Works on Linux, macOS, and Windows runners.
- Aims to be a helper action for "[actions/cache@v2](https://github.com/marketplace/actions/cache)".
- It is also possible to specify a time-limited hash.
- Help us to fix [issues](https://github.com/KEINOS/gh-action-hash-for-cache/issues) @ GitHub.
- View on [marketplace](https://github.com/marketplace/actions/file-hash-for-cache).## Usage
Basic format of the workflow step.
```yaml
jobs:
:strategy:
matrix:
platform: [ubuntu-latest, macos-latest, windows-latest]runs-on: ${{ matrix.platform }}
steps:
- name:
uses: KEINOS/gh-action-hash-for-cache@main
id:
with:
path: |
variant:
```- Exposed variables: `steps..outputs.hash`
## Examples
### On File Change
In this example, if "Dockerfile" is changed, the hash will be changed.
```yaml
- name: Get a hash key from a file
id: hash-now-dont-you-cry
uses: KEINOS/gh-action-hash-for-cache@main
with:
path: ./Dockerfile- name: Activate caching
id: cache
uses: actions/cache@v3
with:
path: /path/target/dir/to/cache/and/restore
key: ${{ steps.hash-now-dont-you-cry.outputs.hash }}
```Multiple target files can be specified. The below example, if "composer.json" or "composer.lock" is changed, the hash will be changed.
```yaml
- name: Get a hash key from two files
id: hash-now-dont-you-cry
uses: KEINOS/gh-action-hash-for-cache@main
with:
path: |
./composer.json
./composer.lock- name: Activate caching
id: cache
uses: actions/cache@v3
with:
path: /path/target/dir/to/cache/and/restore
key: ${{ steps.hash-now-dont-you-cry.outputs.hash }}
```### On Variant Change
In this example, if "go.mod" or "go.sum" is modified **or the value of "variant" is changed**, the hash will be changed.
```yaml
- name: Get hash key
id: hash-now-dont-you-cry
uses: KEINOS/gh-action-hash-for-cache@main
with:
path: |
./go.mod
./go.sum
variant: "v1.0.0"- name: Activate caching
id: cache
uses: actions/cache@v3
with:
path: /path/target/dir/to/cache/and/restore
key: ${{ steps.hash-now-dont-you-cry.outputs.hash }}
```### Time-limitation using variant
In this example, if "go.mod" or "go.sum" is modified **or the month is changed**, the hash will be changed.
- Note that the "TZ" (time zone) can be changed to suit your country.
```yaml
- name: Get hash key
id: hash-now-dont-you-cry
uses: KEINOS/gh-action-hash-for-cache@main
with:
path: |
./go.mod
./go.sum
variant: $(TZ=UTC-9 date '+%Y%m')- name: Activate caching
id: cache
uses: actions/cache@v3
with:
path: /path/target/dir/to/cache/and/restore
key: ${{ steps.hash-now-dont-you-cry.outputs.hash }}
```### View working example
- [workflows/unit-tests.yml](https://github.com/KEINOS/go-argonize/blob/main/.github/workflows/unit-tests.yml) @ [github.com/KEINOS/go-argonize](https://github.com/KEINOS/go-argonize)