Skip to content

Commit

Permalink
Merge pull request #1 from TimonLukas/feature-caching
Browse files Browse the repository at this point in the history
Feature: caching
  • Loading branch information
TimonLukas authored Jun 18, 2022
2 parents 2d23cae + 19989e2 commit bb20c10
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ This GitHub action creates a single-file server that:
fallback: "index.html"
# On launch, open the users preferred browser pointing to this path, `false` to disable
launch: "/"

# Cache redbean executable instead of fetching every time, `false` to disable
cache: true

# Example: static server for `./build/*` without fallback using redbean version x.y.z
- uses: TimonLukas/action-static-redbean@v1
Expand Down
34 changes: 26 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,53 @@ inputs:
launch:
description: "On startup launch preferred browser pointing to this path. Set to `false` to disable."
default: "/"
cache:
description: "Cache redbean executable"
default: true

runs:
using: "composite"
steps:
- run: echo "::set-output name=executable::$(pwd)/${{ inputs.executable-name }}"
- id: paths
shell: bash
id: paths
- run: curl "https://redbean.dev/redbean-${{ inputs.version }}.com" >"${{ steps.paths.outputs.executable }}"
run: |
echo "::set-output name=executable::$(pwd)/${{ inputs.executable-name }}"
echo "::set-output name=temp::$(mktemp -d)"
- if: ${{ inputs.cache }}
id: cache
uses: actions/cache@v3
with:
path: ${{ steps.paths.outputs.temp }}
key: action-static-redbean-${{ inputs.version }} }}
- if: ${{ !inputs.cache || steps.cache.outputs.cache-hit != 'true' }}
run: curl "https://redbean.dev/redbean-${{ inputs.version }}.com" >"${{ steps.paths.outputs.temp }}/redbean.com"
shell: bash
- run: cp "${{ steps.paths.outputs.temp }}/redbean.com" "${{ steps.paths.outputs.executable }}"
shell: bash
- if: ${{ inputs.fallback != false }}
shell: bash
working-directory: ${{ steps.paths.outputs.temp }}
run: |
unzip -qqo "${{ steps.paths.outputs.executable }}" .init.lua
cat <<EOT >> .init.lua
unzip -qq "${{ steps.paths.outputs.executable }}" .init.lua
cat <<EOT >> .init.lua
function OnHttpRequest()
if not RoutePath() then
ServeAsset('${{ inputs.fallback }}')
end
end
end
EOT
zip -qq "${{ steps.paths.outputs.executable }}" .init.lua
rm .init.lua
- if: ${{ inputs.launch != false }}
shell: bash
working-directory: ${{ steps.paths.outputs.temp }}
run: |
unzip -qqo "${{ steps.paths.outputs.executable }}" .init.lua
unzip -qq "${{ steps.paths.outputs.executable }}" .init.lua
echo "LaunchBrowser('${{ inputs.launch }}')" >> .init.lua
zip -qq "${{ steps.paths.outputs.executable }}" .init.lua
rm .init.lua
- run: zip -qq -r "${{ steps.paths.outputs.executable }}" ./**
shell: bash
working-directory: ${{ inputs.input }}

0 comments on commit bb20c10

Please sign in to comment.