|
| 1 | +name: Release Dify Package |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + pull_request: |
| 6 | + types: [opened, synchronize, reopened] |
| 7 | + |
| 8 | +jobs: |
| 9 | + build: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + |
| 12 | + steps: |
| 13 | + - name: Checkout code |
| 14 | + |
| 15 | + with: |
| 16 | + fetch-depth: 0 |
| 17 | + |
| 18 | + - name: Get the latest tag |
| 19 | + id: get_tag |
| 20 | + run: | |
| 21 | + echo "tag=$(git describe --tags --abbrev=0)" >> $GITHUB_OUTPUT |
| 22 | +
|
| 23 | + - name: Check for pre-release |
| 24 | + id: check_prerelease |
| 25 | + env: |
| 26 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 27 | + run: | |
| 28 | + tag=${{ steps.get_tag.outputs.tag }} |
| 29 | + owner=${{ github.repository_owner }} |
| 30 | + repo_name=$(basename `git rev-parse --show-toplevel`) |
| 31 | + release=$(curl -X GET -H "Accept: application/vnd.github.v3+json" \ |
| 32 | + -H "Authorization: token $GITHUB_TOKEN" \ |
| 33 | + https://api.github.com/repos/$owner/$repo_name/releases/tags/$tag) |
| 34 | +
|
| 35 | + if [[ $(echo "$release" | jq -r '.prerelease') != "true" ]]; then |
| 36 | + echo "Pre-release not found for tag $tag. Exiting." |
| 37 | + exit 1 |
| 38 | + fi |
| 39 | +
|
| 40 | + # Store the release URL for uploading assets later |
| 41 | + echo "release_url=$(echo "$release" | jq -r '.upload_url')" >> $GITHUB_OUTPUT |
| 42 | +
|
| 43 | + - name: Check for existing difypkg file |
| 44 | + run: | |
| 45 | + tag=${{ steps.get_tag.outputs.tag }} |
| 46 | + repo_name=$(basename `git rev-parse --show-toplevel`) |
| 47 | + if [ -f "$repo_name-$tag.difypkg" ]; then |
| 48 | + echo "File $repo_name-$tag.difypkg already exists. Exiting." |
| 49 | + exit 0 |
| 50 | + fi |
| 51 | +
|
| 52 | + - name: Get latest release |
| 53 | + id: latest_release |
| 54 | + env: |
| 55 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 56 | + run: | |
| 57 | + response=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ |
| 58 | + https://api.github.com/repos/langgenius/dify-plugin-daemon/releases/latest) |
| 59 | +
|
| 60 | + # Extract browser_download_url which is directly downloadable |
| 61 | + download_url=$(echo $response | jq -r '.assets[] | select(.name == "dify-plugin-linux-amd64") | .browser_download_url') |
| 62 | + echo "download_url=$download_url" >> $GITHUB_OUTPUT |
| 63 | +
|
| 64 | + # Optional: Extract the version for reference |
| 65 | + echo "version=$(echo $response | jq -r '.tag_name')" >> $GITHUB_OUTPUT |
| 66 | +
|
| 67 | + - name: Download Dify Plugin |
| 68 | + run: | |
| 69 | + if [ -z "${{ steps.latest_release.outputs.download_url }}" ]; then |
| 70 | + echo "Asset not found in the latest release. Exiting." |
| 71 | + exit 1 |
| 72 | + fi |
| 73 | + curl -L -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -o dify "${{ steps.latest_release.outputs.download_url }}" |
| 74 | + chmod +x dify |
| 75 | +
|
| 76 | + - name: Run Dify Plugin Package |
| 77 | + run: | |
| 78 | + PLUGIN_DIR=$(pwd) |
| 79 | + cd .. |
| 80 | + ls |
| 81 | + $PLUGIN_DIR/dify plugin package $PLUGIN_DIR |
| 82 | +
|
| 83 | + - name: Set package filename |
| 84 | + id: set_package_file |
| 85 | + run: | |
| 86 | + repo_name=$(basename `git rev-parse --show-toplevel`) |
| 87 | + tag=${{ steps.get_tag.outputs.tag }} |
| 88 | + echo "package_file=$repo_name.difypkg" >> $GITHUB_OUTPUT |
| 89 | +
|
| 90 | + - name: Upload package to GitHub Release |
| 91 | + env: |
| 92 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 93 | + uses: actions/upload-release-asset@v1 |
| 94 | + with: |
| 95 | + upload_url: ${{ steps.check_prerelease.outputs.release_url }} |
| 96 | + asset_path: ./${{ steps.set_package_file.outputs.package_file }} |
| 97 | + asset_name: ${{ steps.set_package_file.outputs.package_file }} |
| 98 | + asset_content_type: application/octet-stream |
0 commit comments