Skip to content

Attempt 2 for loop action #2

Attempt 2 for loop action

Attempt 2 for loop action #2

Workflow file for this run

name: Loop cacheKeys workflow
on: workflow_dispatch:

Check failure on line 2 in .github/workflows/loop.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/loop.yml

Invalid workflow file

You have an error in your yaml syntax on line 2
jobs:
getRepoCacheVars:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Print all var names before change
run: |
for var in "ALTERNATE_BIOMES" "APOTHEOSIS" "APOTHEOSIS_NEW_GAME_PLUS" "APOTHEOSIS_TUONELA" "NEW_GAME_PLUS_HD" "NIGHTMARE_HD" "NOITAVANIA" "NOITAVANIA_NEW_GAME_PLUS" "PURGATORY" "REGULAR_LEFT_PW" "REGULAR_MAIN_BRANCH" "REGULAR_MIDDLE" "REGULAR_RIGHT_PW"; do
echo "${var}_CACHEKEY" # Placeholder echo, actual dynamic access would need scripting support.
- name: Fetch and update cache keys
id: fetch_and_update_cache_keys
run: |
get_modified_on() {
project_name=$1
var_name=${2}_CACHEKEY
response=$(curl --request GET \
--header "Authorization: Bearer ${{ secrets.CF_PAGES_READ_ALL_API }}" \
--header 'Content-Type: application/json' \
--url "https://api.cloudflare.com/client/v4/accounts/${{ secrets.CF_ACCOUNT_ID }}/pages/projects/${project_name}/deployments")
modified_on=$(echo $response | jq -r '.result[0].modified_on' | date -u -f - +%s)
echo "${var_name}=$modified_on" >> $GITHUB_ENV # Use environment variable to pass dynamic value.
}
get_modified_on "project1" "ALTERNATE_BIOMES"
get_modified_on "project2" "APOTHEOSIS"
# Add more calls as necessary.
- name: Update index.html with new cache keys
run: |
new_keys=$(env | grep _CACHEKEY | sed 's/=/":"/g; s/^/{ "/; s/$/" },/')
# Assuming new_keys is formatted as JSON objects. Adjust the string manipulation as necessary.
perl -pi -e "s#<script id=\"cachekeys\">.*?</script>#<script id=\"cachekeys\">const tileCacheKeys = {$new_keys};</script>#s" public/index.html
- name: Commit and push changes if any
run: |
git config --global user.email "action@github.com"
git config --global user.name "GitHub Actions"
git add public/index.html
if [ -z "$(git status --porcelain)" ]; then
echo "No changes to commit"
else
git commit -m "Update index.html with new cache keys"
git push