mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added Github Action that updates copyright year.
This commit is contained in:
parent
f24b0c6237
commit
fe85a8256a
2 changed files with 19 additions and 141 deletions
16
.github/workflows/copyright_year_updater.yml
vendored
Normal file
16
.github/workflows/copyright_year_updater.yml
vendored
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
name: Copyright year updater.
|
||||||
|
|
||||||
|
on:
|
||||||
|
repository_dispatch:
|
||||||
|
types: ["Restart copyright_year_updater workflow."]
|
||||||
|
schedule:
|
||||||
|
# At 03:00 on January 1.
|
||||||
|
- cron: "0 3 1 1 *"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
Copyright-year:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: desktop-app/action_code_updater@master
|
||||||
|
with:
|
||||||
|
type: "license-year"
|
144
.github/workflows/user_agent_updater.yml
vendored
144
.github/workflows/user_agent_updater.yml
vendored
|
@ -5,152 +5,14 @@ on:
|
||||||
types: ["Restart user_agent_updater workflow."]
|
types: ["Restart user_agent_updater workflow."]
|
||||||
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:
|
pull_request_target:
|
||||||
types: [closed]
|
types: [closed]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
User-agent:
|
User-agent:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
env:
|
|
||||||
codeFile: "Telegram/SourceFiles/mtproto/details/mtproto_domain_resolver.cpp"
|
|
||||||
headBranchPrefix: "chrome_"
|
|
||||||
baseBranch: "dev"
|
|
||||||
isPull: "0"
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Set env.
|
- uses: desktop-app/action_code_updater@master
|
||||||
if: startsWith(github.event_name, 'pull_request')
|
|
||||||
run: |
|
|
||||||
echo "isPull=1" >> $GITHUB_ENV
|
|
||||||
|
|
||||||
- name: Clone.
|
|
||||||
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.
|
|
||||||
env:
|
|
||||||
ref: ${{ github.event.pull_request.head.ref }}
|
|
||||||
if: |
|
|
||||||
env.isPull == '1'
|
|
||||||
&& github.event.action == 'closed'
|
|
||||||
&& startsWith(env.ref, env.headBranchPrefix)
|
|
||||||
run: |
|
|
||||||
git push origin --delete $ref
|
|
||||||
|
|
||||||
- name: Write a new version of Google Chrome to the user-agent for DNS.
|
|
||||||
if: env.isPull == '0'
|
|
||||||
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);
|
|
||||||
|
|
||||||
def setEnv(value):
|
|
||||||
open(os.environ['GITHUB_ENV'], "a").write(value);
|
|
||||||
|
|
||||||
def writeUserAgent():
|
|
||||||
p = os.environ['codeFile'];
|
|
||||||
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);
|
|
||||||
|
|
||||||
setEnv("ChromeVersion=" + newChromeVersion);
|
|
||||||
|
|
||||||
writeUserAgent();
|
|
||||||
|
|
||||||
- name: Push to a new branch.
|
|
||||||
if: env.isPull == '0' && env.ChromeVersion != ''
|
|
||||||
run: |
|
|
||||||
git diff > git_diff.txt
|
|
||||||
if [[ ! -s git_diff.txt ]]; then
|
|
||||||
echo "Nothing to commit."
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
git checkout -b $headBranchPrefix$ChromeVersion
|
|
||||||
git add $codeFile
|
|
||||||
git commit -m "Update User-Agent for DNS to Chrome $ChromeVersion."
|
|
||||||
|
|
||||||
git push origin $headBranchPrefix$ChromeVersion
|
|
||||||
echo "Done!"
|
|
||||||
|
|
||||||
- name: Close previous pull requests.
|
|
||||||
if: env.isPull == '0' && env.ChromeVersion != ''
|
|
||||||
uses: actions/github-script@0.4.0
|
|
||||||
with:
|
with:
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
type: "user-agent"
|
||||||
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…
Add table
Reference in a new issue