Fix release.yml

This commit is contained in:
Zhichang Yu 2024-12-07 15:21:12 +08:00
parent 95614175e6
commit 44d4686b20

View File

@ -18,105 +18,107 @@ jobs:
release: release:
runs-on: [ "self-hosted", "overseas" ] runs-on: [ "self-hosted", "overseas" ]
steps: steps:
- name: Ensure workspace ownership - name: Ensure workspace ownership
run: echo "chown -R $USER $GITHUB_WORKSPACE" && sudo chown -R $USER $GITHUB_WORKSPACE run: echo "chown -R $USER $GITHUB_WORKSPACE" && sudo chown -R $USER $GITHUB_WORKSPACE
# https://github.com/actions/checkout/blob/v3/README.md # https://github.com/actions/checkout/blob/v3/README.md
- name: Check out code - name: Check out code
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
token: ${{ secrets.MY_GITHUB_TOKEN }} # Use the secret as an environment variable token: ${{ secrets.MY_GITHUB_TOKEN }} # Use the secret as an environment variable
fetch-depth: 0
fetch-tags: true
- name: Prepare release body - name: Prepare release body
run: | run: |
if [[ $GITHUB_EVENT_NAME == 'create' ]]; then if [[ $GITHUB_EVENT_NAME == 'create' ]]; then
RELEASE_TAG=${GITHUB_REF#refs/tags/} RELEASE_TAG=${GITHUB_REF#refs/tags/}
if [[ $RELEASE_TAG == 'nightly' ]]; then if [[ $RELEASE_TAG == 'nightly' ]]; then
PRERELEASE=true
else
PRERELEASE=false
fi
echo "Workflow triggered by create tag: $RELEASE_TAG"
else
RELEASE_TAG=nightly
PRERELEASE=true PRERELEASE=true
else echo "Workflow triggered by schedule"
PRERELEASE=false
fi fi
echo "Workflow triggered by create tag: $RELEASE_TAG" echo "RELEASE_TAG=$RELEASE_TAG" >> $GITHUB_ENV
else echo "PRERELEASE=$PRERELEASE" >> $GITHUB_ENV
RELEASE_TAG=nightly RELEASE_DATETIME=$(date --rfc-3339=seconds)
PRERELEASE=true echo Release $RELEASE_TAG created from $GITHUB_SHA at $RELEASE_DATETIME > release_body.md
echo "Workflow triggered by schedule"
fi
echo "RELEASE_TAG=$RELEASE_TAG" >> $GITHUB_ENV
echo "PRERELEASE=$PRERELEASE" >> $GITHUB_ENV
RELEASE_DATETIME=$(date --rfc-3339=seconds)
echo Release $RELEASE_TAG created from $GITHUB_SHA at $RELEASE_DATETIME > release_body.md
- name: Move the existing mutable tag - name: Move the existing mutable tag
# https://github.com/softprops/action-gh-release/issues/171 # https://github.com/softprops/action-gh-release/issues/171
run: | run: |
git fetch --tags git fetch --tags
if [[ $GITHUB_EVENT_NAME == 'schedule' ]]; then if [[ $GITHUB_EVENT_NAME == 'schedule' ]]; then
# Determine if a given tag exists and matches a specific Git commit. # Determine if a given tag exists and matches a specific Git commit.
# actions/checkout@v4 fetch-tags doesn't work when triggered by schedule # actions/checkout@v4 fetch-tags doesn't work when triggered by schedule
if [ "$(git rev-parse -q --verify "refs/tags/$RELEASE_TAG")" = "$GITHUB_SHA" ]; then if [ "$(git rev-parse -q --verify "refs/tags/$RELEASE_TAG")" = "$GITHUB_SHA" ]; then
echo "mutable tag $RELEASE_TAG exists and matches $GITHUB_SHA" echo "mutable tag $RELEASE_TAG exists and matches $GITHUB_SHA"
else else
git tag -f $RELEASE_TAG $GITHUB_SHA git tag -f $RELEASE_TAG $GITHUB_SHA
git push -f origin $RELEASE_TAG:refs/tags/$RELEASE_TAG git push -f origin $RELEASE_TAG:refs/tags/$RELEASE_TAG
echo "created/moved mutable tag $RELEASE_TAG to $GITHUB_SHA" echo "created/moved mutable tag $RELEASE_TAG to $GITHUB_SHA"
fi
fi fi
fi
- name: Create or overwrite a release - name: Create or overwrite a release
# https://github.com/actions/upload-release-asset has been replaced by https://github.com/softprops/action-gh-release # https://github.com/actions/upload-release-asset has been replaced by https://github.com/softprops/action-gh-release
uses: softprops/action-gh-release@v2 uses: softprops/action-gh-release@v2
with: with:
token: ${{ secrets.MY_GITHUB_TOKEN }} # Use the secret as an environment variable token: ${{ secrets.MY_GITHUB_TOKEN }} # Use the secret as an environment variable
prerelease: ${{ env.PRERELEASE }} prerelease: ${{ env.PRERELEASE }}
tag_name: ${{ env.RELEASE_TAG }} tag_name: ${{ env.RELEASE_TAG }}
# The body field does not support environment variable substitution directly. # The body field does not support environment variable substitution directly.
body_path: release_body.md body_path: release_body.md
- name: Set up QEMU - name: Set up QEMU
uses: docker/setup-qemu-action@v3 uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3 uses: docker/setup-buildx-action@v3
# https://github.com/marketplace/actions/docker-login # https://github.com/marketplace/actions/docker-login
- name: Login to Docker Hub - name: Login to Docker Hub
uses: docker/login-action@v3 uses: docker/login-action@v3
with: with:
username: infiniflow username: infiniflow
password: ${{ secrets.DOCKERHUB_TOKEN }} password: ${{ secrets.DOCKERHUB_TOKEN }}
# https://github.com/marketplace/actions/build-and-push-docker-images # https://github.com/marketplace/actions/build-and-push-docker-images
- name: Build and push full image - name: Build and push full image
uses: docker/build-push-action@v6 uses: docker/build-push-action@v6
with: with:
context: . context: .
push: true push: true
tags: infiniflow/ragflow:${{ env.RELEASE_TAG }} tags: infiniflow/ragflow:${{ env.RELEASE_TAG }}
file: Dockerfile file: Dockerfile
platforms: linux/amd64 platforms: linux/amd64
# https://github.com/marketplace/actions/build-and-push-docker-images # https://github.com/marketplace/actions/build-and-push-docker-images
- name: Build and push slim image - name: Build and push slim image
uses: docker/build-push-action@v6 uses: docker/build-push-action@v6
with: with:
context: . context: .
push: true push: true
tags: infiniflow/ragflow:${{ env.RELEASE_TAG }}-slim tags: infiniflow/ragflow:${{ env.RELEASE_TAG }}-slim
file: Dockerfile file: Dockerfile
build-args: LIGHTEN=1 build-args: LIGHTEN=1
platforms: linux/amd64 platforms: linux/amd64
- name: Build ragflow-sdk - name: Build ragflow-sdk
if: startsWith(github.ref, 'refs/tags/v') if: startsWith(github.ref, 'refs/tags/v')
run: | run: |
cd sdk/python && \ cd sdk/python && \
poetry build poetry build
- name: Publish package distributions to PyPI - name: Publish package distributions to PyPI
if: startsWith(github.ref, 'refs/tags/v') if: startsWith(github.ref, 'refs/tags/v')
uses: pypa/gh-action-pypi-publish@release/v1 uses: pypa/gh-action-pypi-publish@release/v1
with: with:
packages-dir: dist/ packages-dir: dist/
password: ${{ secrets.PYPI_API_TOKEN }} password: ${{ secrets.PYPI_API_TOKEN }}
verbose: true verbose: true