Publish Filter #4337
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish Filter | |
on: | |
workflow_run: | |
workflows: | |
- "github-release" | |
types: | |
- completed | |
schedule: | |
- cron: '0 */6 * * *' # Every 6 hours | |
workflow_dispatch: | |
permissions: | |
contents: read | |
pages: write | |
id-token: write | |
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 | |
run: | | |
mkdir artifacts && cd artifacts | |
curl -sL $(curl -s https://api.github.com/repos/henrikwidlund/HostsParser/releases/latest | grep browser_download_url | cut -d\" -f4 | grep 'linux-x64.tar.gz$') | tar zx | |
- 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@v5 | |
- name: Upload artifact | |
uses: actions/upload-pages-artifact@v3 | |
with: | |
path: './public' | |
deploy: | |
needs: generate | |
runs-on: ubuntu-latest | |
timeout-minutes: 15 | |
permissions: | |
pages: write | |
id-token: write | |
actions: read | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
steps: | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v4 |