-
Notifications
You must be signed in to change notification settings - Fork 1
190 lines (173 loc) · 7.18 KB
/
release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
name: Create release
on:
workflow_dispatch:
pull_request:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
release:
name: Release to Github
permissions:
contents: write
runs-on: ubuntu-latest
outputs:
version: ${{ steps.set_variables.outputs.version }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: "3.8"
- name: Install Hatch
run: pipx install hatch
- name: Set variables
id: set_variables
run: |
cp README.md plugin/
cd plugin/
metadata=$(hatch project metadata)
echo "::group::Variables"
cat << EOF | tee -a "$GITHUB_OUTPUT"
tag=$(git for-each-ref refs/tags --sort=-creatordate --format='%(refname:strip=2)' --count=1)
version=$(echo ${metadata} | jq -r .version)
project_name=$(echo ${metadata} | jq -r .name)
EOF
echo "::endgroup::"
- name: Bundle
if: github.event_name != 'pull_request' && format('refs/heads/{0}', github.event.repository.default_branch) == github.ref
# only release on default branch
id: bundle
env:
GH_TOKEN: ${{ github.token }}
tag: ${{ steps.set_variables.outputs.tag }}
version: ${{ steps.set_variables.outputs.version }}
project_name: ${{ steps.set_variables.outputs.project_name }}
shell: bash
run: |
cd plugin/
mkdir bundle/
cp -r yt_dlp_plugins bundle/
cd bundle/
find . -type f -name '*.py[co]' -delete -o -type d -name __pycache__ -delete
zip -9 --recurse-paths "${project_name}" *
printf "## What's Changed\n\n" >> CHANGELOG.md
gh pr list --json author,number,title,mergedAt --state merged -R ${{ github.repository }} \
| jq -r --arg authortime "$(git log --format='%at' -n1 ${tag})" \
'.[]|select((.mergedAt|strptime("%Y-%m-%dT%H:%M:%SZ")|mktime)>($authortime|tonumber))| "* \(.title) by @\(.author.login) in #\(.number|tostring)"' \
>> CHANGELOG.md
printf "\n**Full Changelog**: ${{ github.server_url }}/${{ github.repository }}/compare/${tag}...${version}\n" >> CHANGELOG.md
r=$(cat CHANGELOG.md) # <--- Read release Notes
r="${r//'%'/'%25'}" # Multiline escape sequences for %
r="${r//$'\n'/'%0A'}" # Multiline escape sequences for '\n'
r="${r//$'\r'/'%0D'}" # Multiline escape sequences for '\r'
echo "RELEASE_BODY=$r" | tee -a $GITHUB_OUTPUT # <--- Set environment variable
- name: Create Release on Github
if: github.event_name != 'pull_request' && format('refs/heads/{0}', github.event.repository.default_branch) == github.ref
# only release on default branch
uses: svenstaro/upload-release-action@v2
with:
tag: ${{ steps.set_variables.outputs.version }}
release_name: |
${{ steps.set_variables.outputs.project_name }} ${{ steps.set_variables.outputs.version }}
body: ${{ steps.bundle.outputs.RELEASE_BODY }}
file: plugin/bundle/${{ steps.set_variables.outputs.project_name }}.zip
asset_name: ${{ steps.set_variables.outputs.project_name }}.zip
overwrite: true
release_pypi:
name: Release to PyPI
if: github.event_name != 'pull_request' && format('refs/heads/{0}', github.event.repository.default_branch) == github.ref
# only release on default branch
runs-on: ubuntu-latest
permissions:
id-token: write # mandatory for trusted publishing
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build hatchling
- name: Build
run: |
cd plugin/
rm -rf dist/**
printf '%s\n\n' \
"Official repository: <${{ github.server_url }}/${{ github.repository }}>" > ./README.md.new
cat ../README.md >> ./README.md.new && mv -f ./README.md.new ./README.md
python -m build --no-isolation .
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
verbose: true
packages-dir: plugin/dist
release_docker:
name: Build Docker Image
needs: release
runs-on: ubuntu-latest
permissions:
packages: write
env:
repository: ${{ github.repository }} # like `brainicism/bgutil-ytdlp-pot-provider`
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
context: git
images: ${{ env.repository }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
# mark as latest only if built on default branch of repository
type=raw,value=ci,enable={{is_default_branch}}
# mark as ci only if built on default branch of repository
type=raw,value=${{ needs.release.outputs.version }},enable={{is_default_branch}}
# add the new git tag only if built on default branch of repository
type=sha
type=ref,event=branch
type=ref,event=pr
- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push
uses: docker/build-push-action@v6
with:
context: server/
file: server/Dockerfile
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ steps.meta.outputs.annotations }}
- name: Add official repository link to README.md
if: github.event_name != 'pull_request'
run: |
printf '%s\n\n' \
"Official repository: <${{ github.server_url }}/${{ github.repository }}>" > ./README.md.new
cat ./README.md >> ./README.md.new && mv -f ./README.md.new ./README.md
- name: Update repo description
if: github.event_name != 'pull_request'
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
repository: ${{ env.repository }}
short-description: ${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.description'] }}
readme-filepath: README.md