1 Commits

Author SHA1 Message Date
JohnsonRan
87a8165a6a feat: commit to github
Signed-off-by: JohnsonRan <me@ihtw.moe>
2025-08-13 02:21:50 +08:00
2 changed files with 46 additions and 27 deletions

View File

@@ -11,6 +11,9 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
REGISTRY_IMAGE: moontechlab/lunatv
permissions:
contents: write
packages: write
@@ -46,19 +49,14 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set lowercase repository owner
id: lowercase
run: echo "owner=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT"
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ steps.lowercase.outputs.owner }}/lunatv
images: ghcr.io/${{ env.REGISTRY_IMAGE }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=${{ env.latest_tag }},enable=${{ github.ref == 'refs/heads/main' && github.event_name != 'workflow_run' }}
type=semver,pattern=${{ env.latest_tag }},enable=${{ github.ref == 'refs/heads/main' && github.event_name != 'workflow_run' }}
- name: Get latest tag
run: |
@@ -68,6 +66,11 @@ jobs:
jq -r '.[0].name // "latest"' | sed 's/^v//'
)" >> $GITHUB_ENV
- name: Get commit SHA
if: github.ref == 'refs/heads/main'
id: vars
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Build and push by digest
id: build
uses: docker/build-push-action@v5
@@ -76,11 +79,13 @@ jobs:
file: ./Dockerfile
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
tags: ${{ github.event_name != 'workflow_run' && format('ghcr.io/{0}/lunatv:{1}', steps.lowercase.outputs.owner, env.latest_tag) || '' }}
outputs: type=image,name=ghcr.io/${{ steps.lowercase.outputs.owner }}/lunatv,name-canonical=true,push=true
build-args: |
SHA=${{ steps.vars.outputs.sha_short }}
outputs: type=image,name=ghcr.io/${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
- name: Export digest
run: |
rm -rf /tmp/digests
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
@@ -115,28 +120,32 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set lowercase repository owner
id: lowercase
run: echo "owner=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT"
- name: Get latest tag
run: |
echo "latest_tag=$(
curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/tags" | \
jq -r '.[0].name // "latest"' | sed 's/^v//'
)" >> $GITHUB_ENV
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ steps.lowercase.outputs.owner }}/lunatv
images: ghcr.io/${{ env.REGISTRY_IMAGE }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=${{ env.latest_tag }},enable=${{ github.ref == 'refs/heads/main' && github.event_name != 'workflow_run' }}
type=semver,pattern=${{ env.latest_tag }},enable=${{ github.ref == 'refs/heads/main' && github.event_name != 'workflow_run' }}
- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf 'ghcr.io/${{ steps.lowercase.outputs.owner }}/lunatv@sha256:%s ' *)
$(printf 'ghcr.io/${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ghcr.io/${{ steps.lowercase.outputs.owner }}/lunatv:${{ steps.meta.outputs.version }}
docker buildx imagetools inspect ghcr.io/${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
cleanup:
runs-on: ubuntu-latest

View File

@@ -33,9 +33,6 @@ jobs:
echo "Tag: $TAG_NAME"
- name: Get tag message
id: tag_message
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TAG_NAME=${{ steps.version.outputs.tag }}
RELEASE_BODY=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
@@ -69,6 +66,7 @@ jobs:
else
cp /tmp/new_entry.txt CHANGELOG
fi
rm CHANGELOG.bak
echo "✅ Updated CHANGELOG with new entry for version $VERSION"
echo "Updating VERSION.txt..."
@@ -82,15 +80,27 @@ jobs:
sed -i "s/const CURRENT_VERSION = '[^']*';/const CURRENT_VERSION = '$VERSION';/" src/lib/version.ts
echo "✅ Updated version.ts to $VERSION"
- name: Commit generated files
- name: Commit to Codeberg
run: |
git config --local user.email "${{ secrets.PUSH_EMAIL }}"
git config --local user.name "${{ secrets.PUSH_NAME }}"
git add CHANGELOG VERSION.txt src/lib/changelog.ts src/lib/version.ts
if git diff --staged --quiet; then
echo "No changes to commit"
else
git commit -m "chore: Bump to ${{ steps.version.outputs.version }}"
git push https://${{ secrets.PUSH_TOKEN }}@${{ secrets.REPO_URL }}.git HEAD:main
echo "Committed and pushed generated files"
fi
git commit -m "chore: Bump to ${{ steps.version.outputs.version }}"
git push https://${{ secrets.PUSH_TOKEN }}@${{ secrets.REPO_URL }}.git HEAD:main
rm -rf .git
- name: Checkout
uses: actions/checkout@v5
with:
path: 'github'
ref: 'main'
- name: Commit to Github
run: |
cd github
cp ../{CHANGELOG,VERSION.txt} .
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add CHANGELOG VERSION.txt
git commit -m "chore: Bump to ${{ steps.version.outputs.version }}"
git push -u https://${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git main