mirror of
https://github.com/meeb/tubesync.git
synced 2025-06-23 13:36:35 +00:00
Merge pull request #889 from tcely/patch-10
Move `yt-dlp` API work to an action
This commit is contained in:
commit
82918e8b09
5
.github/actions/FFmpeg/action.yml
vendored
5
.github/actions/FFmpeg/action.yml
vendored
@ -45,14 +45,15 @@ runs:
|
|||||||
id: 'set'
|
id: 'set'
|
||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ inputs.token }}
|
GH_TOKEN: ${{ inputs.token }}
|
||||||
|
GH_REPO: '${{ inputs.repository_owner }}/${{ inputs.repository_name }}'
|
||||||
GH_API_GQL_ASSETS: '${{ inputs.num-assets }}'
|
GH_API_GQL_ASSETS: '${{ inputs.num-assets }}'
|
||||||
GH_API_GQL_RELEASES: '${{ inputs.num-releases }}'
|
GH_API_GQL_RELEASES: '${{ inputs.num-releases }}'
|
||||||
GH_API_GQL_OWNER: '${{ inputs.repository_owner }}'
|
GH_API_GQL_OWNER: '${{ inputs.repository_owner }}'
|
||||||
GH_API_GQL_REPO: '${{ inputs.repository_name }}'
|
GH_API_GQL_REPO: '${{ inputs.repository_name }}'
|
||||||
shell: 'bash'
|
shell: 'bash'
|
||||||
run: |
|
run: |
|
||||||
command -v gh
|
command -v gh >/dev/null ;
|
||||||
command -v jq
|
command -v jq >/dev/null ;
|
||||||
gql_query='query($repo: String!, $owner: String!, $releases: Int!, $assets: Int!) { repository(owner: $owner, name: $repo) { releases(first: $releases, orderBy: { field: CREATED_AT, direction: DESC }) { nodes { tagName, isDraft, isPrerelease, isLatest, tag { name, target { oid, commitUrl } }, releaseAssets(first: $assets) { totalCount, nodes { name, size, downloadUrl } } } } } }' ;
|
gql_query='query($repo: String!, $owner: String!, $releases: Int!, $assets: Int!) { repository(owner: $owner, name: $repo) { releases(first: $releases, orderBy: { field: CREATED_AT, direction: DESC }) { nodes { tagName, isDraft, isPrerelease, isLatest, tag { name, target { oid, commitUrl } }, releaseAssets(first: $assets) { totalCount, nodes { name, size, downloadUrl } } } } } }' ;
|
||||||
gql_jq='[ .data.repository.releases.nodes[] | select((.isLatest or .isDraft or .isPrerelease) | not) | { "tag": .tag.name, "commit": .tag.target.oid, "date": .tag.name[1+(.tag.name|index("-")):], "assets": { "limit": '"${GH_API_GQL_ASSETS}"', "totalCount": .releaseAssets.totalCount }, "files": .releaseAssets.nodes, "versions": [ .releaseAssets.nodes[].name | select(contains("-linux64-"))[1+index("-"):index("-linux64-")] ] } ]' ;
|
gql_jq='[ .data.repository.releases.nodes[] | select((.isLatest or .isDraft or .isPrerelease) | not) | { "tag": .tag.name, "commit": .tag.target.oid, "date": .tag.name[1+(.tag.name|index("-")):], "assets": { "limit": '"${GH_API_GQL_ASSETS}"', "totalCount": .releaseAssets.totalCount }, "files": .releaseAssets.nodes, "versions": [ .releaseAssets.nodes[].name | select(contains("-linux64-"))[1+index("-"):index("-linux64-")] ] } ]' ;
|
||||||
mk_delim() { printf -- '"%s_EOF_%d_"' "$1" "${RANDOM}" ; } ;
|
mk_delim() { printf -- '"%s_EOF_%d_"' "$1" "${RANDOM}" ; } ;
|
||||||
|
84
.github/actions/yt-dlp/action.yml
vendored
Normal file
84
.github/actions/yt-dlp/action.yml
vendored
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
name: 'yt-dlp Releases'
|
||||||
|
description: 'Use GitHub CLI & API to retrieve information about `yt-dlp` releases.'
|
||||||
|
|
||||||
|
inputs:
|
||||||
|
token:
|
||||||
|
required: true
|
||||||
|
default: ${{ github.token }}
|
||||||
|
description: |
|
||||||
|
GH_TOKEN for GitHub CLI to use.
|
||||||
|
Default: `\$\{\{ github.token \}\}`
|
||||||
|
num-releases:
|
||||||
|
required: true
|
||||||
|
default: '25'
|
||||||
|
description: |
|
||||||
|
The number of releases to retrieve from the repository.
|
||||||
|
Default: 25
|
||||||
|
repository_owner:
|
||||||
|
required: true
|
||||||
|
default: 'yt-dlp'
|
||||||
|
description: |
|
||||||
|
The name of the user or organization that owns the repository.
|
||||||
|
Default: 'yt-dlp'
|
||||||
|
repository_name:
|
||||||
|
required: true
|
||||||
|
default: 'yt-dlp'
|
||||||
|
description: |
|
||||||
|
Which repository from the owner to search for releases.
|
||||||
|
Default: 'yt-dlp'
|
||||||
|
|
||||||
|
outputs:
|
||||||
|
latest-release:
|
||||||
|
value: ${{ steps.set.outputs.latest-release }}
|
||||||
|
description: 'The JSON API response for the latest release.'
|
||||||
|
releases:
|
||||||
|
value: ${{ steps.set.outputs.releases }}
|
||||||
|
description: 'Retrieved JSON from the API describing the releases.'
|
||||||
|
|
||||||
|
runs:
|
||||||
|
using: 'composite'
|
||||||
|
steps:
|
||||||
|
- name: Retrieve releases
|
||||||
|
id: 'set'
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ inputs.token }}
|
||||||
|
GH_API_GQL_RELEASES: '${{ inputs.num-releases }}'
|
||||||
|
GH_API_GQL_OWNER: '${{ inputs.repository_owner }}'
|
||||||
|
GH_API_GQL_REPO: '${{ inputs.repository_name }}'
|
||||||
|
shell: 'bash'
|
||||||
|
run: |
|
||||||
|
command -v gh > /dev/null ;
|
||||||
|
command -v jq > /dev/null ;
|
||||||
|
gql_query='query($repo: String!, $owner: String!, $releases: Int!) { repository(owner: $owner, name: $repo) { releases(first: $releases, orderBy: { field: CREATED_AT, direction: DESC }) { nodes { name, createdAt, publishedAt, updatedAt, tagName, url, isDraft, isPrerelease, isLatest, tag { name, target { oid, commitUrl } } } } } }' ;
|
||||||
|
gql_jq='[ .data.repository.releases.nodes[] | select((.isDraft or .isPrerelease) | not) | del(.isDraft, .isPrerelease) ]' ;
|
||||||
|
mk_delim() { printf -- '"%s_EOF_%d_"' "$1" "${RANDOM}" ; } ;
|
||||||
|
open_ml_var() { local f=''\%'s<<'\%'s\n' ; printf -- "${f}" "$2" "$1" ; } ;
|
||||||
|
close_ml_var() { local f='%s\n' ; printf -- "${f}" "$1" ; } ;
|
||||||
|
{
|
||||||
|
var='releases' ;
|
||||||
|
delim="$(mk_delim "${var}")" ;
|
||||||
|
open_ml_var "${delim}" "${var}" ;
|
||||||
|
gh api graphql --cache 12h \
|
||||||
|
-F owner="${GH_API_GQL_OWNER}" \
|
||||||
|
-F repo="${GH_API_GQL_REPO}" \
|
||||||
|
-F releases="${GH_API_GQL_RELEASES}" \
|
||||||
|
-f query="${gql_query}" --jq "${gql_jq}" ;
|
||||||
|
close_ml_var "${delim}" "${var}" ;
|
||||||
|
jq_arg='map(select(.isLatest))[0]' ;
|
||||||
|
var='latest-release' ;
|
||||||
|
delim="$(mk_delim "${var}")" ;
|
||||||
|
open_ml_var "${delim}" "${var}" ;
|
||||||
|
gh api graphql --cache 12h \
|
||||||
|
-F owner="${GH_API_GQL_OWNER}" \
|
||||||
|
-F repo="${GH_API_GQL_REPO}" \
|
||||||
|
-F releases="${GH_API_GQL_RELEASES}" \
|
||||||
|
-f query="${gql_query}" --jq "${gql_jq}" | jq -c "${jq_arg}" -- ;
|
||||||
|
close_ml_var "${delim}" "${var}" ;
|
||||||
|
unset -v delim jq_arg var ;
|
||||||
|
} >> "${GITHUB_OUTPUT}" ;
|
||||||
|
# Log the human version
|
||||||
|
gh api graphql --cache 12h \
|
||||||
|
-F owner="${GH_API_GQL_OWNER}" \
|
||||||
|
-F repo="${GH_API_GQL_REPO}" \
|
||||||
|
-F releases="${GH_API_GQL_RELEASES}" \
|
||||||
|
-f query="${gql_query}" --jq "${gql_jq}" | jq '.[]' -- ;
|
40
.github/workflows/ci.yaml
vendored
40
.github/workflows/ci.yaml
vendored
@ -55,45 +55,7 @@ jobs:
|
|||||||
uses: ./.github/actions/FFmpeg
|
uses: ./.github/actions/FFmpeg
|
||||||
- name: Retrieve yt-dlp/yt-dlp releases with GitHub CLI
|
- name: Retrieve yt-dlp/yt-dlp releases with GitHub CLI
|
||||||
id: yt-dlp
|
id: yt-dlp
|
||||||
env:
|
uses: ./.github/actions/yt-dlp
|
||||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
GH_API_GQL_RELEASES: 25
|
|
||||||
GH_API_GQL_OWNER: yt-dlp
|
|
||||||
GH_API_GQL_REPO: yt-dlp
|
|
||||||
run: |
|
|
||||||
gql_query='query($repo: String!, $owner: String!, $releases: Int!) { repository(owner: $owner, name: $repo) { releases(first: $releases, orderBy: { field: CREATED_AT, direction: DESC }) { nodes { name, createdAt, publishedAt, updatedAt, tagName, url, isDraft, isPrerelease, isLatest, tag { name, target { oid, commitUrl } } } } } }' ;
|
|
||||||
gql_jq='[ .data.repository.releases.nodes[] | select((.isDraft or .isPrerelease) | not) | del(.isDraft, .isPrerelease) ]' ;
|
|
||||||
mk_delim() { printf -- '"%s_EOF_%d_"' "$1" "${RANDOM}" ; } ;
|
|
||||||
open_ml_var() { local f=''\%'s<<'\%'s\n' ; printf -- "${f}" "$2" "$1" ; } ;
|
|
||||||
close_ml_var() { local f='%s\n' ; printf -- "${f}" "$1" ; } ;
|
|
||||||
{
|
|
||||||
var='releases' ;
|
|
||||||
delim="$(mk_delim "${var}")" ;
|
|
||||||
open_ml_var "${delim}" "${var}" ;
|
|
||||||
gh api graphql --cache 12h \
|
|
||||||
-F owner="${GH_API_GQL_OWNER}" \
|
|
||||||
-F repo="${GH_API_GQL_REPO}" \
|
|
||||||
-F releases="${GH_API_GQL_RELEASES}" \
|
|
||||||
-f query="${gql_query}" --jq "${gql_jq}" ;
|
|
||||||
close_ml_var "${delim}" "${var}" ;
|
|
||||||
jq_arg='map(select(.isLatest))[0]' ;
|
|
||||||
var='latest-release' ;
|
|
||||||
delim="$(mk_delim "${var}")" ;
|
|
||||||
open_ml_var "${delim}" "${var}" ;
|
|
||||||
gh api graphql --cache 12h \
|
|
||||||
-F owner="${GH_API_GQL_OWNER}" \
|
|
||||||
-F repo="${GH_API_GQL_REPO}" \
|
|
||||||
-F releases="${GH_API_GQL_RELEASES}" \
|
|
||||||
-f query="${gql_query}" --jq "${gql_jq}" | jq -c "${jq_arg}" -- ;
|
|
||||||
close_ml_var "${delim}" "${var}" ;
|
|
||||||
unset -v delim jq_arg var ;
|
|
||||||
} >> "${GITHUB_OUTPUT}" ;
|
|
||||||
# Log the human version
|
|
||||||
gh api graphql --cache 12h \
|
|
||||||
-F owner="${GH_API_GQL_OWNER}" \
|
|
||||||
-F repo="${GH_API_GQL_REPO}" \
|
|
||||||
-F releases="${GH_API_GQL_RELEASES}" \
|
|
||||||
-f query="${gql_query}" --jq "${gql_jq}" | jq '.[]' -- ;
|
|
||||||
|
|
||||||
test:
|
test:
|
||||||
if: ${{ !cancelled() && ( 'pull_request' != github.event_name || (! github.event.pull_request.draft) ) }}
|
if: ${{ !cancelled() && ( 'pull_request' != github.event_name || (! github.event.pull_request.draft) ) }}
|
||||||
|
Loading…
Reference in New Issue
Block a user