From 42456f6389a74e1c0b8df5f9929f766aa408664c Mon Sep 17 00:00:00 2001 From: tcely Date: Fri, 16 May 2025 04:21:33 -0400 Subject: [PATCH 1/4] Update release.yaml --- .github/workflows/release.yaml | 88 ++++++++++++++++++++++++++++------ 1 file changed, 73 insertions(+), 15 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 9e2992d7..dea6c23f 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -8,31 +8,89 @@ on: types: [published] jobs: - containerise: + info: runs-on: ubuntu-latest + outputs: + ffmpeg-date: ${{ steps.jq.outputs.FFMPEG_DATE }} + ffmpeg-releases: ${{ steps.ffmpeg.outputs.releases }} + ffmpeg-version: ${{ steps.jq.outputs.FFMPEG_VERSION }} + lowercase-github-actor: ${{ steps.github-actor.outputs.lowercase }} + lowercase-github-repository_owner: ${{ steps.github-repository_owner.outputs.lowercase }} + tag: ${{ steps.tag.outputs.tag }} + ytdlp-latest-release: ${{ steps.yt-dlp.outputs.latest-release }} + ytdlp-releases: ${{ steps.yt-dlp.outputs.releases }} steps: - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - name: Get tag id: tag uses: dawidd6/action-get-tag@v1 - - uses: docker/build-push-action@v2 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - name: Log into GitHub Container Registry - run: echo "${{ secrets.REGISTRY_ACCESS_TOKEN }}" | docker login https://ghcr.io -u ${{ github.actor }} --password-stdin - - name: Lowercase github username for ghcr - id: string - uses: ASzc/change-string-case-action@v1 + - uses: actions/checkout@v4 + - name: Lowercase github username + id: github-actor + uses: ./.github/actions/string-case with: string: ${{ github.actor }} + - name: Lowercase github repository owner + id: github-repository_owner + uses: ./.github/actions/string-case + with: + string: ${{ github.repository_owner }} + - name: Retrieve yt-dlp/FFmpeg-Builds releases with GitHub CLI + id: ffmpeg + uses: ./.github/actions/FFmpeg + - name: Retrieve yt-dlp/yt-dlp releases with GitHub CLI + id: yt-dlp + uses: ./.github/actions/yt-dlp + - name: Set outputs with jq + id: jq + run: | + cat >| .ffmpeg.releases.json <<'EOF' + ${{ steps.ffmpeg.outputs.releases }} + EOF + mk_delim() { local f='%s_EOF_%d_' ; printf -- "${f}" "$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='FFMPEG_DATE' ; + delim="$(mk_delim "${var}")" ; + open_ml_var "${delim}" "${var}" ; + jq_arg='[foreach .[] as $release ([{}, []]; [ .[0] + {($release.commit): ([ $release.date ] + (.[0][($release.commit)] // []) ) }, [ .[1][0] // $release.commit ] ] ; .[0][(.[1][0])] ) ][-1][0]' ; + jq -r "${jq_arg}" -- .ffmpeg.releases.json ; + close_ml_var "${delim}" "${var}" ; + + ffmpeg_date="$( jq -r "${jq_arg}" -- .ffmpeg.releases.json )" + + var='FFMPEG_VERSION' ; + delim="$(mk_delim "${var}")" ; + open_ml_var "${delim}" "${var}" ; + jq_arg='.[]|select(.date == $date)|.versions[]|select(startswith("N-"))' ; + jq -r --arg date "${ffmpeg_date}" "${jq_arg}" -- .ffmpeg.releases.json ; + close_ml_var "${delim}" "${var}" ; + unset -v delim jq_arg var ; + } >> "${GITHUB_OUTPUT}" + cat -v "${GITHUB_OUTPUT}" + rm -v -f .ffmpeg.releases.json + + containerise: + needs: ['info'] + runs-on: ubuntu-latest + steps: + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Log into GitHub Container Registry + run: echo "${{ secrets.REGISTRY_ACCESS_TOKEN }}" | docker login https://ghcr.io -u ${{ github.actor }} --password-stdin - name: Build and push - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v6 with: platforms: linux/amd64,linux/arm64 push: true - tags: ghcr.io/${{ steps.string.outputs.lowercase }}/${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.tag }} - cache-from: type=registry,ref=ghcr.io/${{ steps.string.outputs.lowercase }}/${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.tag }} - cache-to: type=inline + tags: ghcr.io/${{ needs.info.outputs.lowercase-github-actor }}/${{ env.IMAGE_NAME }}:${{ needs.info.outputs.tag }} + cache-from: | + type=registry,ref=ghcr.io/${{ needs.info.outputs.lowercase-github-repository_owner }}/${{ env.IMAGE_NAME }}:latest + type=gha build-args: | IMAGE_NAME=${{ env.IMAGE_NAME }} + FFMPEG_DATE=${{ needs.info.outputs.ffmpeg-date }} + FFMPEG_VERSION=${{ needs.info.outputs.ffmpeg-version }} + YTDLP_DATE=${{ fromJSON(needs.info.outputs.ytdlp-latest-release).tag.name }} From e0e81c3a2c39742c6f8d88d92c43ff0ca36b53fa Mon Sep 17 00:00:00 2001 From: tcely Date: Fri, 16 May 2025 04:59:55 -0400 Subject: [PATCH 2/4] Create get-tag/action.yml --- .github/actions/get-tag/action.yml | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 .github/actions/get-tag/action.yml diff --git a/.github/actions/get-tag/action.yml b/.github/actions/get-tag/action.yml new file mode 100644 index 00000000..59ab43f3 --- /dev/null +++ b/.github/actions/get-tag/action.yml @@ -0,0 +1,41 @@ +name: Get tag +description: Get tag name from GITHUB_REF environment variable +inputs: + strip_v: + required: false + default: false + description: Whether to strip "v" from the tag or not +outputs: + tag: + value: ${{ steps.set.outputs.tag }} + description: Git tag name + +runs: + using: 'composite' + steps: + - name: Set outputs + id: 'set' + env: + INPUT_STRIP_V '${{ inputs.strip_v }}' + shell: 'bash' + run: | + tag="${GITHUB_REF}" + printf -- 'Manipulating string: %s\n' "${tag}" + test -n "${tag}" || exit 1 + + case "${tag}" in + (refs/tags/*) tag="${tag#refs/tags/}" ;; + (*) printf -- 'Not a tag ref\n' ; exit 2 ;; + esac + + if [ 'true' = "${INPUT_STRIP_V,,}" ] + then + tag="${tag#[Vv]}" + fi + + set_sl_var() { local f='%s=%s\n' ; printf -- "${f}" "$@" ; } ; + + set_sl_var tag "${tag}" >> "${GITHUB_OUTPUT}" + + set_sl_var 'tag ' " ${tag}" + From 4d179fbd427c0a559bd7cd634f346f50f16560c6 Mon Sep 17 00:00:00 2001 From: tcely Date: Fri, 16 May 2025 05:03:24 -0400 Subject: [PATCH 3/4] Use the local `get-tag` action --- .github/workflows/release.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index dea6c23f..621c31a5 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -20,10 +20,10 @@ jobs: ytdlp-latest-release: ${{ steps.yt-dlp.outputs.latest-release }} ytdlp-releases: ${{ steps.yt-dlp.outputs.releases }} steps: + - uses: actions/checkout@v4 - name: Get tag id: tag - uses: dawidd6/action-get-tag@v1 - - uses: actions/checkout@v4 + uses: ./.github/actions/get-tag - name: Lowercase github username id: github-actor uses: ./.github/actions/string-case From 7923d03387aca14ef0c50c29e464b00aff726297 Mon Sep 17 00:00:00 2001 From: tcely Date: Fri, 16 May 2025 05:09:15 -0400 Subject: [PATCH 4/4] fixup: missing colon --- .github/actions/get-tag/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/get-tag/action.yml b/.github/actions/get-tag/action.yml index 59ab43f3..7f554c70 100644 --- a/.github/actions/get-tag/action.yml +++ b/.github/actions/get-tag/action.yml @@ -16,7 +16,7 @@ runs: - name: Set outputs id: 'set' env: - INPUT_STRIP_V '${{ inputs.strip_v }}' + INPUT_STRIP_V: '${{ inputs.strip_v }}' shell: 'bash' run: | tag="${GITHUB_REF}"