Skip to content

Commit

Permalink
Build/push ARM images
Browse files Browse the repository at this point in the history
  • Loading branch information
Brainicism committed Sep 9, 2024
1 parent 904590e commit 39308d1
Showing 1 changed file with 156 additions and 152 deletions.
308 changes: 156 additions & 152 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Create release
on:
on:
workflow_dispatch:
pull_request:

Expand All @@ -16,107 +16,107 @@ jobs:
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
- 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
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
- 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
Expand All @@ -125,62 +125,66 @@ jobs:
permissions:
packages: write
env:
repository: ${{ github.repository }} # like `brainicism/bgutil-ytdlp-pot-provider`
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: Build and push
uses: docker/build-push-action@v6
with:
context: server/
file: server/Dockerfile
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
- 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

0 comments on commit 39308d1

Please sign in to comment.