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

View File

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