Skip to content

Build

Build #181

name: Sync LosslessCut Release
on:
workflow_dispatch: {}
schedule:
- cron: '0 0 * * Sun'
push:
branches:
- main
paths-ignore:
- 'README.md'
- '.github/workflows/create_release.yaml'
permissions:
contents: write
actions: read
jobs:
check_new_release:
runs-on: ubuntu-latest
outputs:
check_new_release_found: ${{ steps.compare.outputs.new_release }}
tag_name: ${{ steps.get_release.outputs.tag_name }}
asset_url: ${{ steps.get_release.outputs.asset_url }}
rls_body: ${{ steps.get_release.outputs.rls_body }}
steps:
# Checkout the repository
- name: Checkout Repository
uses: actions/checkout@v3
- name: Get Latest Release Info
id: get_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Fetching latest release from mifi/lossless-cut..."
RELEASE_INFO=$(gh api repos/mifi/lossless-cut/releases/latest)
TAG_NAME=$(echo "$RELEASE_INFO" | jq -r .tag_name)
RLS_BODY=$(echo "$RELEASE_INFO" | jq -r .body)
ASSET_URL=$(echo "$RELEASE_INFO" | jq -r '.assets[] | select(.name | endswith("win-x64.7z")) | .browser_download_url')
if [ -z "$ASSET_URL" ]; then
echo "No .7z asset found in the latest release."
exit 1
fi
echo "Latest release tag: $TAG_NAME"
echo "Asset URL: $ASSET_URL"
echo "RLS Body: $RLS_BODY"
# Use a delimiter to preserve newlines in rls_body
echo "rls_body<<EOF" >> $GITHUB_OUTPUT
echo "$RLS_BODY" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT
echo "asset_url=$ASSET_URL" >> $GITHUB_OUTPUT
- name: Compare Release Version
id: compare
env:
TAG_NAME: ${{ steps.get_release.outputs.tag_name }}
run: |
echo "Retrieving latest processed version..."
if [ -f LATEST_RELEASE ]; then
LATEST_PROCESSED_VERSION=$(cat LATEST_RELEASE)
else
LATEST_PROCESSED_VERSION=""
fi
echo "Latest processed version: $LATEST_PROCESSED_VERSION"
echo "New release version: $TAG_NAME"
if [ "$LATEST_PROCESSED_VERSION" == "$TAG_NAME" ]; then
echo "No new release found. Exiting."
echo "new_release=false" >> $GITHUB_OUTPUT
else
echo "New release found. Proceeding."
echo "new_release=true" >> $GITHUB_OUTPUT
fi
sync_release:
runs-on: ubuntu-latest
needs: [check_new_release]
if: needs.check_new_release.outputs.check_new_release_found == 'true'
steps:
# Checkout the repository
- name: Checkout Repository
uses: actions/checkout@v3
# Use outputs from the check_new_release job (avoids refetching)
# Download the .7z asset
- name: Download .7z Asset
env:
ASSET_URL: ${{ needs.check_new_release.outputs.asset_url }}
run: |
echo "Downloading .7z file..."
curl -L "$ASSET_URL" --output losslesscut.7z
# Extract the .7z archive
- name: Extract 7zip Archive
run: |
sudo apt-get update && sudo apt-get install -y p7zip-full
mkdir losslesscut_extracted
7z x -olosslesscut_extracted losslesscut.7z
# Create a .zip file with the version number in the file name
- name: Create Zip Archive with Version
id: create_zip
env:
TAG_NAME: ${{ needs.check_new_release.outputs.tag_name }}
run: |
ZIP_FILENAME="losslesscut-$TAG_NAME.zip"
cd losslesscut_extracted
zip -r "../$ZIP_FILENAME" ./*
cd ..
echo "Created zip file: $ZIP_FILENAME"
echo "zip_filename=$ZIP_FILENAME" >> $GITHUB_OUTPUT
# Create a release and upload the .zip file
- name: Create Release and Upload Asset
uses: ncipollo/release-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag: "losslesscut-${{ needs.check_new_release.outputs.tag_name }}"
name: "LosslessCut ${{ needs.check_new_release.outputs.tag_name }}"
body: ${{ needs.check_new_release.outputs.rls_body }}
draft: false
prerelease: false
artifacts: ${{ steps.create_zip.outputs.zip_filename }}
# Save the processed version
- name: Save Processed Release Version
run: echo "${{ needs.check_new_release.outputs.tag_name }}" > LATEST_RELEASE
# Commit and push the updated version file
- name: Commit and Push Version File
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add LATEST_RELEASE
git commit -m "Update latest processed release to ${{ needs.check_new_release.outputs.tag_name }}"
git push