GithubHelp home page GithubHelp logo

animmouse / tool-cache Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 4.0 40 KB

Implementation of Tool Cache in composite GitHub Actions

Home Page: https://github.com/marketplace/actions/tool-cache

License: Mozilla Public License 2.0

Shell 39.38% PowerShell 60.62%
github-actions actions action tool-cache

tool-cache's Introduction

Tool Cache in Composite Action

Implementation of actions/tool-cache toolkit in composite GitHub Actions.

A Tool Cache for composite-based GitHub Actions.

This action supports Ubuntu, Windows, and macOS.

Rationale

The purpose of this action is to provide composite-based actions an easy way to install programs on GitHub Actions.

JavaScript-based actions already have actions/tool-cache toolkit to facilitate in installing programs in GitHub Actions.

With this tool cache action, you don't need to worry writing a code in installing the program and adding it to PATH, you just download the program and extract it to a folder inside runner temp, just like actions/tool-cache toolkit.

Usage

  1. Create a folder with the name of the program you want to install inside ${{ runner.temp }}.
  2. Extract all of the files required by the program to that folder inside ${{ runner.temp }} you have created.
  3. Run this action with the name of the folder inside ${{ runner.temp }} you used to extract all the files needed for the program.

Example workflow

steps:
  - name: Download Hello World binary (Unix-like)
    if: runner.os == 'Linux' || runner.os == 'macOS'
    working-directory: ${{ runner.temp }}
    run: |
      if [ $RUNNER_OS = macOS ]; then os=macos; else os=linux; fi
      mkdir hello-world
      wget -O hello-world/hello $GITHUB_SERVER_URL/AnimMouse/Hello-World-Binaries/raw/main/hello-$os
      chmod +x hello-world/hello
      
  - name: Download Hello World binary (Windows)
    if: runner.os == 'Windows'
    working-directory: ${{ runner.temp }}
    run: |
      New-Item hello-world -ItemType Directory
      Invoke-WebRequest $env:GITHUB_SERVER_URL/AnimMouse/Hello-World-Binaries/raw/main/hh2.golden.exe -OutFile hello-world\hello.exe
      
  - name: Install the Hello World binary using tool-cache
    uses: AnimMouse/tool-cache@v1
    with:
      folder_name: hello-world

Example workflow with cache

steps:
  - name: Restore Hello World cache
    id: cache
    uses: actions/cache/restore@v3
    with:
      path: ${{ runner.tool_cache }}/hello-world
      key: hello-world-${{ runner.os }}
      
  - name: Download Hello World binary (Unix-like)
    if: (runner.os == 'Linux' || runner.os == 'macOS') && ! steps.cache.outputs.cache-hit
    working-directory: ${{ runner.temp }}
    run: |
      if [ $RUNNER_OS = macOS ]; then os=macos; else os=linux; fi
      mkdir hello-world
      wget -O hello-world/hello $GITHUB_SERVER_URL/AnimMouse/Hello-World-Binaries/raw/main/hello-$os
      chmod +x hello-world/hello
      
  - name: Download Hello World binary (Windows)
    if: runner.os == 'Windows' && ! steps.cache.outputs.cache-hit
    working-directory: ${{ runner.temp }}
    run: |
      New-Item hello-world -ItemType Directory
      Invoke-WebRequest $env:GITHUB_SERVER_URL/AnimMouse/Hello-World-Binaries/raw/main/hh2.golden.exe -OutFile hello-world\hello.exe
      
  - name: Install the Hello World binary using tool-cache
    uses: AnimMouse/tool-cache@v1
    with:
      folder_name: hello-world
      cache_hit: ${{ steps.cache.outputs.cache-hit }}
      
  - name: Save Hello World cache
    if: '! steps.cache.outputs.cache-hit'
    uses: actions/cache/save@v3
    with:
      path: ${{ runner.tool_cache }}/hello-world
      key: hello-world-${{ runner.os }}

You can check the .github/workflows/test.yaml file inside this repository to see how it works by installing a Hello World program.
You can also check actions that uses this tool cache.

Used by

  1. AnimMouse/setup-rclone
  2. AnimMouse/setup-cloudflared
  3. AnimMouse/setup-yt-dlp
  4. AnimMouse/setup-restic
  5. AnimMouse/setup-youtubeuploader
  6. AnimMouse/setup-appimage
  7. AnimMouse/setup-ffmpeg
  8. AnimMouse/setup-age

Similar actions

  1. supplypike/setup-bin
  2. pbrisbin/setup-tool-action
  3. jcwillox/install-tool-action
  4. prantlf/install-release-action

tool-cache's People

Contributors

animmouse avatar dcarbone avatar steve-todorov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

tool-cache's Issues

Installation steps fail on self-hosted windows machines

Hey,

This action fails on self-hosted agents, because in your windows ps script you assume the environment is always "clean".
Unfortunately this is not true when you have self-hosted runners which are not disposable. In those cases your installation script will fail with the following:

Installing Rclone to tool cache
  
        Directory: C:\actions-runner\_work\_tool
    
  Mode                 LastWriteTime         Length Name                                                                 
  ----                 -------------         ------ ----                                                                 
  d-----         3/23/2023  11:35 AM                Rclone                                                               
  Move-Item : Cannot create a file when that file already exists.
  At C:\actions-runner\_work\_actions\AnimMouse\tool-cache\v1\scripts\install\Windows.ps1:5 char:1
  + Move-Item $env:RUNNER_TEMP\$env:folder_name\* $env:RUNNER_TOOL_CACHE\ ...
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : WriteError: (C:\actions-runn...lone\rclone.exe:FileInfo) [Move-Item], IOException
      + FullyQualifiedErrorId : MoveFileInfoItemIOError,Microsoft.PowerShell.Commands.MoveItemCommand

And then in AnimMouse/setup-rclone:

Installing Rclone to tool cache

Run & $env:GITHUB_ACTION_PATH\scripts\add-to-path\Windows.ps1
Adding Rclone tool cache folder to path
Run & $env:GITHUB_ACTION_PATH\scripts\sign-in\Windows.ps1
Signing in to Rclone using Rclone config
  New-Item : An item with the specified name C:\Users\ADF VM\AppData\Roaming\rclone already exists.
  At C:\actions-runner\_work\_actions\steve-todorov\setup-rclone\issues\3\scripts\sign-in\Windows.ps1:4 char:1
  + New-Item $env:APPDATA\rclone -ItemType Directory
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : ResourceExists: (C:\Users\ADF VM\AppData\Roaming\rclone:String) [New-Item], IOException
      + FullyQualifiedErrorId : DirectoryExist,Microsoft.PowerShell.Commands.NewItemCommand

The way to fix it is by removing the target directory so that it will always be "clean" or by forcing the creation of folders (in the case of the sign-in script)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.