Clean branch cache #233
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Clean branch cache | |
on: | |
workflow_dispatch : | |
inputs: | |
branch: | |
description: 'Name of the branch for which removing the cache' | |
required: true | |
delete: | |
branches: | |
- '**' | |
permissions: | |
contents: read | |
jobs: | |
clean-cache: | |
runs-on: ubuntu-latest | |
permissions: | |
# Needed to delete cache from action | |
actions: write | |
contents: read | |
steps: | |
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 | |
- name: Clean Branch Cache | |
if: inputs.branch || github.event.ref_type == 'branch' | |
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | |
env: | |
branchName: ${{ inputs.branch || github.event.ref }} | |
hash: ${{ hashFiles('package.json', 'tsconfig.base.json', 'tsconfig.build.json', 'nx.json') }} | |
with: | |
script: | | |
const globalKey = '${{ runner.os }}-build-' + process.env.hash + '-global-' + process.env.branchName; | |
const testKey = '${{ runner.os }}-build-' + process.env.hash + '-test-' + process.env.branchName; | |
const lintKey = '${{ runner.os }}-build-' + process.env.hash + '-lint-' + process.env.branchName; | |
const [owner, repo] = '${{ github.repository }}'.split('/'); | |
github.rest.actions.deleteActionsCacheByKey({key: globalKey, owner, repo}).catch((e) => console.error(e)); | |
github.rest.actions.deleteActionsCacheByKey({key: testKey, owner, repo}).catch((e) => console.error(e)); | |
github.rest.actions.deleteActionsCacheByKey({key: lintKey, owner, repo}).catch((e) => console.error(e)); |