2020-09-04 23:49:59 +00:00
|
|
|
name: User-agent updater.
|
|
|
|
|
|
|
|
on:
|
|
|
|
repository_dispatch:
|
|
|
|
types: ["Restart user_agent_updater workflow."]
|
|
|
|
schedule:
|
|
|
|
# At 00:00 on day-of-month 1.
|
|
|
|
- cron: '0 0 1 * *'
|
2020-10-24 23:58:59 +00:00
|
|
|
pull_request_target:
|
|
|
|
types: [closed]
|
2020-09-04 23:49:59 +00:00
|
|
|
|
|
|
|
jobs:
|
|
|
|
User-agent:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
|
|
|
env:
|
2020-10-24 23:58:59 +00:00
|
|
|
codeFile: "Telegram/SourceFiles/mtproto/details/mtproto_domain_resolver.cpp"
|
|
|
|
headBranchPrefix: "chrome_"
|
|
|
|
baseBranch: "dev"
|
|
|
|
isPull: "0"
|
2020-09-04 23:49:59 +00:00
|
|
|
|
|
|
|
steps:
|
2020-10-24 23:58:59 +00:00
|
|
|
- name: Set env.
|
|
|
|
if: startsWith(github.event_name, 'pull_request')
|
|
|
|
run: |
|
|
|
|
echo "isPull=1" >> $GITHUB_ENV
|
|
|
|
|
2020-09-04 23:49:59 +00:00
|
|
|
- name: Clone.
|
|
|
|
uses: actions/checkout@v2
|
|
|
|
|
2020-10-24 23:58:59 +00:00
|
|
|
- name: Set up git.
|
|
|
|
run: |
|
|
|
|
token=${{ secrets.TOKEN_FOR_MASTER_UPDATER }}
|
|
|
|
if [ -z "${token}" ]; then
|
|
|
|
echo "Token is unset. Nothing to do."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
url=https://x-access-token:$token@github.com/$GITHUB_REPOSITORY
|
|
|
|
|
|
|
|
git config --global user.email "action@github.com"
|
|
|
|
git config --global user.name "GitHub Action"
|
|
|
|
|
|
|
|
git remote set-url origin $url
|
|
|
|
|
|
|
|
- name: Delete branch.
|
2020-11-26 14:03:51 +00:00
|
|
|
env:
|
|
|
|
ref: ${{ github.event.pull_request.head.ref }}
|
2020-10-24 23:58:59 +00:00
|
|
|
if: |
|
|
|
|
env.isPull == '1'
|
|
|
|
&& github.event.action == 'closed'
|
2020-11-26 14:03:51 +00:00
|
|
|
&& startsWith(env.ref, env.headBranchPrefix)
|
2020-10-24 23:58:59 +00:00
|
|
|
run: |
|
2020-11-26 14:03:51 +00:00
|
|
|
git push origin --delete $ref
|
2020-10-24 23:58:59 +00:00
|
|
|
|
2020-09-04 23:49:59 +00:00
|
|
|
- name: Write a new version of Google Chrome to the user-agent for DNS.
|
2020-10-24 23:58:59 +00:00
|
|
|
if: env.isPull == '0'
|
2020-09-04 23:49:59 +00:00
|
|
|
shell: python
|
|
|
|
run: |
|
|
|
|
import subprocess, os, re;
|
|
|
|
|
|
|
|
regExpVersion = "[0-9]+.[0-9]+.[0-9]+.[0-9]+";
|
|
|
|
chrome = "Chrome/";
|
|
|
|
|
|
|
|
def newVersion():
|
|
|
|
output = subprocess.check_output(["google-chrome", "--version"]);
|
|
|
|
version = re.search(regExpVersion, output);
|
|
|
|
if not version:
|
|
|
|
print("Can't find a Chrome version.");
|
|
|
|
exit();
|
|
|
|
return version.group(0);
|
|
|
|
|
|
|
|
newChromeVersion = newVersion();
|
|
|
|
print(newChromeVersion);
|
|
|
|
|
2020-10-24 23:58:59 +00:00
|
|
|
def setEnv(value):
|
|
|
|
open(os.environ['GITHUB_ENV'], "a").write(value);
|
|
|
|
|
2020-09-04 23:49:59 +00:00
|
|
|
def writeUserAgent():
|
2020-10-24 23:58:59 +00:00
|
|
|
p = os.environ['codeFile'];
|
2020-09-04 23:49:59 +00:00
|
|
|
w = open(p, "r");
|
|
|
|
content = w.read();
|
|
|
|
w.close();
|
|
|
|
|
|
|
|
regExpChrome = chrome + regExpVersion;
|
|
|
|
|
|
|
|
version = re.search(regExpChrome, content);
|
|
|
|
if not version:
|
|
|
|
print("Can't find an user-agent in the code.");
|
|
|
|
exit();
|
|
|
|
content = re.sub(regExpChrome, chrome + newChromeVersion, content);
|
|
|
|
|
|
|
|
w = open(p, "w");
|
|
|
|
w.write(content);
|
|
|
|
|
2020-10-24 23:58:59 +00:00
|
|
|
setEnv("ChromeVersion=" + newChromeVersion);
|
2020-09-04 23:49:59 +00:00
|
|
|
|
|
|
|
writeUserAgent();
|
|
|
|
|
2020-10-24 23:58:59 +00:00
|
|
|
- name: Push to a new branch.
|
|
|
|
if: env.isPull == '0' && env.ChromeVersion != ''
|
2020-09-04 23:49:59 +00:00
|
|
|
run: |
|
|
|
|
git diff > git_diff.txt
|
|
|
|
if [[ ! -s git_diff.txt ]]; then
|
|
|
|
echo "Nothing to commit."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2020-10-24 23:58:59 +00:00
|
|
|
git checkout -b $headBranchPrefix$ChromeVersion
|
|
|
|
git add $codeFile
|
2020-09-04 23:49:59 +00:00
|
|
|
git commit -m "Update User-Agent for DNS to Chrome $ChromeVersion."
|
|
|
|
|
2020-10-24 23:58:59 +00:00
|
|
|
git push origin $headBranchPrefix$ChromeVersion
|
2020-09-04 23:49:59 +00:00
|
|
|
echo "Done!"
|
2020-10-24 23:58:59 +00:00
|
|
|
|
|
|
|
- name: Close previous pull requests.
|
|
|
|
if: env.isPull == '0' && env.ChromeVersion != ''
|
|
|
|
uses: actions/github-script@0.4.0
|
|
|
|
with:
|
|
|
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
script: |
|
|
|
|
const common = {
|
|
|
|
owner: context.repo.owner,
|
|
|
|
repo: context.repo.repo,
|
|
|
|
};
|
|
|
|
|
|
|
|
github.pulls.list(common).then(response => {
|
|
|
|
response.data.forEach((item, _) => {
|
|
|
|
if (item.head.ref.startsWith(process.env.headBranchPrefix)) {
|
|
|
|
console.log(`Close ${item.title} #${item.number}.`);
|
|
|
|
github.pulls.update({
|
|
|
|
pull_number: item.number,
|
|
|
|
state: "closed",
|
|
|
|
...common
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
- name: Create a new pull request.
|
|
|
|
if: env.isPull == '0' && env.ChromeVersion != ''
|
|
|
|
uses: actions/github-script@0.4.0
|
|
|
|
with:
|
|
|
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
script: |
|
|
|
|
const version = process.env.ChromeVersion;
|
|
|
|
const title = `Update User-Agent for DNS to Chrome ${version}.`;
|
|
|
|
|
|
|
|
github.pulls.create({
|
|
|
|
title: title,
|
|
|
|
body: "",
|
|
|
|
head: `${process.env.headBranchPrefix}${version}`,
|
|
|
|
base: process.env.baseBranch,
|
|
|
|
owner: context.repo.owner,
|
|
|
|
repo: context.repo.repo,
|
|
|
|
});
|