Try uploading built content to Releases

This commit is contained in:
iBug 2020-07-27 01:08:27 +08:00
parent 209345282f
commit 5ca13387a5
3 changed files with 56 additions and 13 deletions

View File

@ -5,21 +5,29 @@ on:
branches:
- master
schedule:
- cron: "0 12 * * 6" # 4 AM CST every Saturday
- cron: "0 20 * * 5" # 4 AM CST every Saturday
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Prepare build
run:
git clone --branch=dist "https://${GITHUB_ACTOR}:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git" dist
- run: python3 build.py
- name: Push back to GitHub
run: |
cd dist
git add --all
git -c user.name=GitHub -c user.email=noreply@github.com commit \
-m "Auto build from GitHub Actions run ${GITHUB_RUN_NUMBER}"
git push
- name: Generate release info
id: release-info
run: python3 release-info.py
env:
TZ: Asia/Shanghai
- uses: actions/create-release@v1
id: create_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.release-info.outputs.tag_name }}
release_name: ${{ steps.release-info.outputs.release_name }}
body_path: ${{ steps.release-info.outputs.body_path }}
- uses: csexton/release-asset-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
pattern: 'dist/*'
release-url: ${{ steps.create_release.outputs.upload_url }}

View File

@ -36,8 +36,7 @@ def main():
code = f.read()
code = code.replace("@@TIME@@", now.isoformat()[:-7])
if not os.path.exists(OUT_DIR):
os.mkdir(OUT_DIR, mode=0o755)
os.makedirs(OUT_DIR, mode=0o755, exist_ok=True)
for key in SOURCES:
print(f"Generating PAC script from source {key}")
try:

36
release-info.py Executable file
View File

@ -0,0 +1,36 @@
#!/usr/bin/python3
import sys
import time
import os
RELEASE_MARKDOWN_PATH = "release-info.md"
def create_output(name, content, target=sys.stdout):
print(f"::set-output name={name}::{content}", file=target)
def main():
# Credits: https://stackoverflow.com/a/1398742/5958455
# Depends on os.environ["TZ"]
time.tzset()
now = time.localtime(time.time())
create_output("tag_name", "release-{}".format(time.strftime("%Y%m%d", now)))
create_output("release_name", "Release {}".format(time.strftime("%Y-%m-%d", now)))
create_output("body_path", RELEASE_MARKDOWN_PATH)
# Produce the markdown
with open(RELEASE_MARKDOWN_PATH, "w") as f:
body = "This is an automatic release created from GitHub Actions run {} on {} ({})".format(
os.environ.get("GITHUB_RUN_NUMBER", "<unknown>"),
time.strftime("%B %-d, %Y", now),
os.environ.get("TZ", "UTC"),
)
print(body, file=f)
if __name__ == '__main__':
main()