Changed behavior of user-agent updater to open pull requests.
This commit is contained in:
parent
bcc11d7850
commit
1a2afda09c
|
@ -6,22 +6,53 @@ on:
|
||||||
schedule:
|
schedule:
|
||||||
# At 00:00 on day-of-month 1.
|
# At 00:00 on day-of-month 1.
|
||||||
- cron: '0 0 1 * *'
|
- cron: '0 0 1 * *'
|
||||||
|
pull_request_target:
|
||||||
|
types: [closed]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
User-agent:
|
User-agent:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
env:
|
env:
|
||||||
code_file: "Telegram/SourceFiles/mtproto/details/mtproto_domain_resolver.cpp"
|
codeFile: "Telegram/SourceFiles/mtproto/details/mtproto_domain_resolver.cpp"
|
||||||
skip: "0"
|
headBranchPrefix: "chrome_"
|
||||||
|
baseBranch: "dev"
|
||||||
|
isPull: "0"
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
- name: Set env.
|
||||||
|
if: startsWith(github.event_name, 'pull_request')
|
||||||
|
run: |
|
||||||
|
echo "isPull=1" >> $GITHUB_ENV
|
||||||
|
|
||||||
- name: Clone.
|
- name: Clone.
|
||||||
if: env.skip == '0'
|
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- 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.
|
||||||
|
if: |
|
||||||
|
env.isPull == '1'
|
||||||
|
&& github.event.action == 'closed'
|
||||||
|
&& startsWith(github.head_ref, env.headBranchPrefix)
|
||||||
|
run: |
|
||||||
|
git push origin --delete ${{ github.head_ref }}
|
||||||
|
|
||||||
- name: Write a new version of Google Chrome to the user-agent for DNS.
|
- name: Write a new version of Google Chrome to the user-agent for DNS.
|
||||||
if: env.skip == '0'
|
if: env.isPull == '0'
|
||||||
shell: python
|
shell: python
|
||||||
run: |
|
run: |
|
||||||
import subprocess, os, re;
|
import subprocess, os, re;
|
||||||
|
@ -40,8 +71,11 @@ jobs:
|
||||||
newChromeVersion = newVersion();
|
newChromeVersion = newVersion();
|
||||||
print(newChromeVersion);
|
print(newChromeVersion);
|
||||||
|
|
||||||
|
def setEnv(value):
|
||||||
|
open(os.environ['GITHUB_ENV'], "a").write(value);
|
||||||
|
|
||||||
def writeUserAgent():
|
def writeUserAgent():
|
||||||
p = os.environ['code_file'];
|
p = os.environ['codeFile'];
|
||||||
w = open(p, "r");
|
w = open(p, "r");
|
||||||
content = w.read();
|
content = w.read();
|
||||||
w.close();
|
w.close();
|
||||||
|
@ -57,34 +91,64 @@ jobs:
|
||||||
w = open(p, "w");
|
w = open(p, "w");
|
||||||
w.write(content);
|
w.write(content);
|
||||||
|
|
||||||
print("::set-env name=ChromeVersion::" + newChromeVersion);
|
setEnv("ChromeVersion=" + newChromeVersion);
|
||||||
|
|
||||||
writeUserAgent();
|
writeUserAgent();
|
||||||
|
|
||||||
- name: Push to the current branch.
|
- name: Push to a new branch.
|
||||||
if: env.skip == '0' && env.ChromeVersion != ''
|
if: env.isPull == '0' && env.ChromeVersion != ''
|
||||||
run: |
|
run: |
|
||||||
token=${{ secrets.TOKEN_FOR_MASTER_UPDATER }}
|
|
||||||
if [ -z "${token}" ]; then
|
|
||||||
echo "Token is unset. Nothing to do."
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
url=https://x-access-token:$token@github.com/$GITHUB_REPOSITORY
|
|
||||||
|
|
||||||
git config --local user.email "action@github.com"
|
|
||||||
git config --local user.name "GitHub Action"
|
|
||||||
|
|
||||||
git diff > git_diff.txt
|
git diff > git_diff.txt
|
||||||
if [[ ! -s git_diff.txt ]]; then
|
if [[ ! -s git_diff.txt ]]; then
|
||||||
echo "Nothing to commit."
|
echo "Nothing to commit."
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
git add $code_file
|
git checkout -b $headBranchPrefix$ChromeVersion
|
||||||
|
git add $codeFile
|
||||||
git commit -m "Update User-Agent for DNS to Chrome $ChromeVersion."
|
git commit -m "Update User-Agent for DNS to Chrome $ChromeVersion."
|
||||||
|
|
||||||
git remote set-url origin $url
|
git push origin $headBranchPrefix$ChromeVersion
|
||||||
|
|
||||||
git push origin HEAD:$GITHUB_REF
|
|
||||||
echo "Done!"
|
echo "Done!"
|
||||||
|
|
||||||
|
- 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,
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in New Issue