Skip to content

Publish Filter

Publish Filter #7382

name: Publish Filter
on:
workflow_run:
workflows:
- "github-release"
types:
- completed
schedule:
- cron: '0 */6 * * *' # Every 6 hours
workflow_dispatch:
concurrency:
group: "pages"
cancel-in-progress: true
jobs:
generate:
runs-on: ubuntu-latest
timeout-minutes: 15
if: github.ref == 'refs/heads/main'
steps:
- name: Download latest release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
mkdir artifacts
latest_release_tag=$(gh release list --repo henrikwidlund/hostsparser --limit 1 --json tagName --jq '.[0].tagName')
if [ -z "$latest_release_tag" ]; then
echo "No releases found in henrikwidlund/hostsparser" >&2
exit 1
fi
gh release download --repo henrikwidlund/hostsparser "$latest_release_tag" \
--pattern "*linux-amd64.tar.gz" \
--dir ./artifacts
archive=(./artifacts/*linux-amd64.tar.gz)
if [ ! -f "${archive[0]}" ]; then
echo "No release archive found in ./artifacts" >&2
exit 1
fi
gh attestation verify "${archive[0]}" --repo henrikwidlund/hostsparser
tar -xzf "${archive[0]}" -C ./artifacts
rm "${archive[0]}"
- name: Create public directory
run: mkdir ./public
- name: Create filters
run: |
cat << EOF > temp_script.sh
#!/bin/bash
process_config() {
filename="\$1"
./artifacts/HostsParser "\$1"
CONFIG_FILE=\$(echo "\$filename" | cut -d'/' -f 4)
CONFIG=\${CONFIG_FILE//json/txt}
# Default filter doesn't map to the file name of the config, it's just "filter.txt"
if [[ ! -f "\$CONFIG" ]]; then
CONFIG="filter.txt"
fi
cp "\$CONFIG" ./public/"\$CONFIG"
}
process_config \$1
EOF
chmod +x temp_script.sh
NUM_PROCESSORS=$(nproc)
find ./artifacts/Configurations -name '*.json' -print0 | xargs -0 -I{} -P"$NUM_PROCESSORS" ./temp_script.sh "{}"
rm temp_script.sh
- name: Setup Pages
uses: actions/configure-pages@45bfe0192ca1faeb007ade9deae92b16b8254a0d # v6.0.0
- name: Upload artifact
uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5.0.0
with:
path: './public'
deploy:
needs: generate
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@cd2ce8fcbc39b97be8ca5fce6e763baed58fa128 # v5.0.0