Skip to content

Create a PR if there are changes in effective_tld_names file #2

Create a PR if there are changes in effective_tld_names file

Create a PR if there are changes in effective_tld_names file #2

name: Create a PR if there are changes in effective_tld_names file
on:
schedule:
- cron: '0 6 1,15 * *'
workflow_dispatch:
inputs:
branchName:
description: 'Branch used as target for automation'
required: true
default: 'main'
jobs:
build:
runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: [3.9]
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
token: ${{ secrets.GITHUB_TOKEN }}
ref: ${{ github.event.inputs.branchName }}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Compare file in repo with file upstream
run: |
echo "Fetch latest file version"
curl -o tmp.dat "https://raw.githubusercontent.com/publicsuffix/list/master/public_suffix_list.dat"
file_in_repo=firefox-ios/Shared/effective_tld_names.dat
files_diff=$(cmp --silent tmp.dat $file_in_repo && echo '### SUCCESS: Files Are Identical! ###' || echo '### WARNING: Files Are Different! ###')
echo $files_diff
echo "current_date=$current_date" >> $GITHUB_ENV
if [[ "$files_diff" == *"Different"* ]]; then
echo "Files are different"
echo "create_pr=true" >> $GITHUB_ENV
cp tmp.dat firefox-ios/Shared/effective_tld_names.dat
echo "branch_name=refactor-update-effective-tld-names" >> $GITHUB_ENV
echo "pr_body=This automated PR updates the effective_tld_names file" >> $GITHUB_ENV
rm tmp.dat
fi
- name: Determine PR Version Number
id: versioning
run: |
# This step is used to determine the next version number for the PR title
# The output includes debugging for the piped commands that generate
# the version number and the last line is the version number itself
output=$(bash test-fixtures/ci/get-next-pr-version)
echo "$output"
next_version=$(echo "$output" | tail -n 1) # get the last line of the output
echo "Next version is: v${next_version}"
echo "next_version=${next_version}" >> $GITHUB_ENV
- name: Add Modified File to PR
if: ${{ env.create_pr }}
run: |-
git diff || (git add firefox-ios/Shared/effective_tld_names.dat)
- name: Create Pull Request
if: ${{ env.create_pr }}
uses: peter-evans/create-pull-request@v6
with:
author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
committer: GitHub <[email protected]>
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: ${{ env.pr_title }}
title: "Refactor [v${{ env.next_version }}] Update effective_tld_names file ${{ env.current_date }}"
branch: ${{ env.branch_name }}
body: ${{ env.pr_body }}