Skip to content

Commit

Permalink
Add prefix flag. Fix #6
Browse files Browse the repository at this point in the history
  • Loading branch information
khammami committed Mar 1, 2024
1 parent e0806ab commit cdb3476
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
10 changes: 10 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ jobs:
source: ${{env.GDOC_ID}}
environment: kiosk

# elements-default-path will be replaced by elements-path in case you use -prefix
- name: claat (single document - test min inputs - prefix)
uses: ./
with:
auth: ${{ steps.auth.outputs.access_token }}
source: ${{env.GDOC_ID}}
prefix: https://codelabs-enetcom.khammami.tn/
elements-path: elements/codelab-elements
elements-default-path: claat-public

- name: claat (codelabs.json)
uses: ./
with:
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ claat help
| `ga4id` | Google Analytics v4 ID <br> Default (action): `''` <br> Default (claat):`not implimented` | No |
| `codelabs-json` | Path to a JSON file containing a list of Google document IDs. <br> Default (action): `''` | No |
| `format` | Export format (html, md, offline or all). <br> Default (action): `html` <br> Default (claat): `html` | No |
| `environment` | codelab environment <br> Default (action): `` <br> Default (claat):`web` | No |
| `environment` | codelab environment <br> Default (action): `''` <br> Default (claat):`web` | No |
| `prefix` | URL prefix for html format <br> Default (action): `''` <br> Default (claat):`https://storage.googleapis.com` | No |
| `elements-path` | Local path (JS and CSS) of codelab elements. (in case Google prefix is broken) <br> Default (action): `elements/codelab-elements` | No |
| `elements-default-path` | External path (JS and CSS) of codelab elements. (hosted by Google) <br> Default (action): `claat-public` | No |

## Example Usage

Expand Down
35 changes: 35 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,24 @@ inputs:
Default is ''
required: false
default: ""
prefix:
description: |
URL prefix for html format.
Default is ''
required: false
default: ""
elements-path:
description: |
Local path (JS and CSS) of codelab elements. (in case Google prefix is broken)
Default is 'elements/codelab-elements'
required: false
default: "elements/codelab-elements"
elements-default-path:
description: |
External path (JS and CSS) of codelab elements. (hosted by Google)
Default is 'claat-public'
required: false
default: "claat-public"

runs:
using: "composite"
Expand Down Expand Up @@ -116,12 +134,14 @@ runs:
FORMAT: ${{ inputs.format }}
ENVIRONMENT: ${{ inputs.environment }}
COMMAND: ${{ inputs.command }}
PREFIX: ${{ inputs.prefix }}
run: |
echo "::group::Build command"
claat_command="claat ${COMMAND}"
[[ -n "$ENVIRONMENT" ]] && claat_command+=" -e \"$ENVIRONMENT\""
[[ -n "$GAID" ]] && claat_command+=" -ga \"$GAID\""
[[ "$FORMAT" == "md" ]] && claat_command+=" -f \"$FORMAT\""
[[ -n "$PREFIX" ]] && claat_command+=" -prefix \"$PREFIX\""
[[ -n "$AUTH" ]] && claat_command+=" -auth \"$AUTH\""
echo "CLAAT_COMMAND=$claat_command" >> $GITHUB_ENV
echo "::endgroup::"
Expand Down Expand Up @@ -170,6 +190,21 @@ runs:
echo "Missing ga4id in html format has been added."
echo "::endgroup::"
- name: Fix local path of codelab elements
shell: bash
if: ${{ contains(fromJSON('["html", "all"]'), inputs.format) && inputs.prefix != '' && inputs.elements-path != '' && inputs.elements-default-path != ''}}
working-directory: ${{ inputs.codelabs-path }}
env:
EXTERNAL_PATH: ${{ inputs.elements-default-path }}
LOCAL_PATH: ${{ inputs.elements-path }}
run: |
echo "::group::Fix elements local path"
find . -type f -name "index.html" -print0 | while IFS= read -r -d '' file; do
sed -i "s/${EXTERNAL_PATH//\//\\\/}/${LOCAL_PATH//\//\\\/}/g" "$file"
done
echo "The default local path of codelab elements in html format has been replaced."
echo "::endgroup::"
# Ref: https://haya14busa.github.io/github-action-brandings/
branding:
icon: "upload"
Expand Down

0 comments on commit cdb3476

Please sign in to comment.