Build filter #1935
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: Build filter | |
on: | |
workflow_dispatch: | |
inputs: | |
FORCE_BUILD: | |
description: Force filter build | |
type: boolean | |
default: false | |
DRY_RUN: | |
description: Dry run without push | |
type: boolean | |
default: false | |
schedule: | |
- cron: 0 2,5,8,11,16 * * * # Run at 9, 12, 15, 18, 23 hour in UTC + 7 | |
push: | |
branches: [master, single] | |
env: | |
NEED_BUILD_MASTER: ${{inputs.FORCE_BUILD || false}} | |
NEED_BUILD_SINGLE: ${{inputs.FORCE_BUILD || false}} | |
DRY_RUN: ${{inputs.DRY_RUN || false}} | |
jobs: | |
build_filter_master: | |
if: ${{ github.repository_owner == 'abpvn' && (contains(fromJSON('["schedule", "workflow_dispatch"]'), github.event_name) || contains(github.event.head_commit.message, '[build]') || contains(github.event.head_commit.message, '(#')) }} | |
runs-on: ubuntu-latest | |
outputs: | |
NEED_BUILD_MASTER: ${{steps.check_build.outputs.NEED_BUILD_MASTER}} | |
steps: | |
- uses: hoang-rio/set-timezone@v1.4 | |
with: | |
timezoneLinux: "Asia/Ho_Chi_Minh" | |
- uses: actions/checkout@v4 | |
with: | |
ref: master | |
fetch-depth: 0 | |
- name: Check need to build | |
id: check_build | |
if: ${{ env.NEED_BUILD_MASTER == 'false'}} | |
working-directory: ./filter | |
run: | | |
bash build.sh | |
DIFF_STAT=$(git diff --stat abpvn_ublock.txt) | |
DIFF_STAT_CONTENT=$(git diff --stat abpvn_content_blocker.txt) | |
echo $DIFF_STAT | |
echo $DIFF_STAT_CONTENT | |
if [[ "$DIFF_STAT" != *"| 6 +++---"* || "$DIFF_STAT_CONTENT" != *"| 6 +++---"* ]]; then | |
echo "Need build to update to latest version" | |
NEED_BUILD_MASTER=true | |
echo "NEED_BUILD_MASTER=$NEED_BUILD_MASTER" >> $GITHUB_ENV | |
else | |
echo "Nothing to build" | |
fi | |
git checkout . | |
if [ '${{env.DRY_RUN}}' == 'false' ]; then | |
echo "NEED_BUILD_MASTER=$NEED_BUILD_MASTER" >> $GITHUB_OUTPUT | |
fi | |
- name: Build filter | |
if: ${{ env.NEED_BUILD_MASTER == 'true' }} | |
continue-on-error: true | |
run: | | |
git config user.name github-actions | |
git config user.email github-actions@github.com | |
BUILD_OUTPUT=$(bash commit.sh true) | |
GIT_TAG=$(cat version) | |
git commit -m "Auto build filter on master to $GIT_TAG" | |
git tag $GIT_TAG | |
if [ '${{env.DRY_RUN}}' == 'false' ]; then | |
git push origin master | |
git push origin $GIT_TAG | |
fi | |
DEL_VERSIONS='' | |
REGEX=These[[:space:]]tag[[:space:]]should[[:space:]]be[[:space:]]delete[[:space:]]manualy:[[:space:]]'(.*)' | |
[[ ${BUILD_OUTPUT} =~ $REGEX ]] && \ | |
DEL_VERSIONS=${BASH_REMATCH[1]} | |
DEL_VERSIONS=$(echo "$DEL_VERSIONS" | sed -e "s/'//g") | |
echo "Version to delete: $DEL_VERSIONS" | |
if [ "$DEL_VERSIONS" != "" ]; then | |
if [ '${{env.DRY_RUN}}' == 'false' ]; then | |
git push -d origin $DEL_VERSIONS | |
fi | |
fi | |
build_filter_single: | |
if: ${{ github.repository_owner == 'abpvn' && (contains(fromJSON('["schedule", "workflow_dispatch"]'), github.event_name) || contains(github.event.head_commit.message, '[build]')) }} | |
runs-on: ubuntu-latest | |
outputs: | |
NEED_BUILD_SINGLE: ${{steps.check_build.outputs.NEED_BUILD_SINGLE}} | |
steps: | |
- uses: hoang-rio/set-timezone@v1.4 | |
with: | |
timezoneLinux: "Asia/Ho_Chi_Minh" | |
- uses: actions/checkout@v4 | |
with: | |
ref: single | |
fetch-depth: 0 | |
- name: Check need to build | |
id: check_build | |
if: ${{ env.NEED_BUILD_SINGLE == 'false'}} | |
working-directory: ./filter | |
run: | | |
bash build.sh | |
DIFF_STAT=$(git diff --stat abpvn_ublock.txt) | |
DIFF_STAT_CONTENT=$(git diff --stat abpvn_content_blocker.txt) | |
echo $DIFF_STAT | |
echo $DIFF_STAT_CONTENT | |
if [[ "$DIFF_STAT" != *"| 6 +++---"* || "$DIFF_STAT_CONTENT" != *"| 6 +++---"* ]]; then | |
echo "Need build to update to latest version" | |
NEED_BUILD_SINGLE=true | |
echo "NEED_BUILD_SINGLE=$NEED_BUILD_SINGLE" >> $GITHUB_ENV | |
else | |
echo "Nothing to build" | |
fi | |
git checkout . | |
if [ '${{env.DRY_RUN}}' == 'false' ]; then | |
echo "NEED_BUILD_SINGLE=$NEED_BUILD_SINGLE" >> $GITHUB_OUTPUT | |
fi | |
- name: Build filter | |
if: ${{ env.NEED_BUILD_SINGLE == 'true' }} | |
continue-on-error: true | |
run: | | |
git config user.name github-actions | |
git config user.email github-actions@github.com | |
BUILD_OUTPUT=$(bash commit.sh true) | |
GIT_TAG=$(cat version) | |
git commit -m "Auto build filter on single to $GIT_TAG" | |
git tag $GIT_TAG | |
if [ '${{env.DRY_RUN}}' == 'false' ]; then | |
git push origin single | |
git push origin $GIT_TAG | |
fi | |
DEL_VERSIONS='' | |
REGEX=These[[:space:]]tag[[:space:]]should[[:space:]]be[[:space:]]delete[[:space:]]manualy:[[:space:]]'(.*)' | |
[[ ${BUILD_OUTPUT} =~ $REGEX ]] && \ | |
DEL_VERSIONS=${BASH_REMATCH[1]} | |
DEL_VERSIONS=$(echo "$DEL_VERSIONS" | sed -e "s/'//g") | |
echo "Version to delete: $DEL_VERSIONS" | |
if [ "$DEL_VERSIONS" != "" ]; then | |
if [ '${{env.DRY_RUN}}' == 'false' ]; then | |
git push -d origin $DEL_VERSIONS | |
fi | |
fi | |
update_server_filter: | |
runs-on: ubuntu-latest | |
needs: [build_filter_master, build_filter_single] | |
if: ${{ needs.build_filter_master.outputs.NEED_BUILD_MASTER == 'true' || needs.build_filter_single.outputs.NEED_BUILD_SINGLE == 'true' }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Request to server | |
run: bash pull.sh |