From e461e0ead56fb8ae1337dae7b6526ee66a8cd139 Mon Sep 17 00:00:00 2001 From: Jonathan LEI Date: Mon, 28 Aug 2023 12:52:44 +0000 Subject: [PATCH] ci: automatically publish release --- .github/workflows/release.yml | 119 ++++++++++++++++++++++++---------- 1 file changed, 83 insertions(+), 36 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 99e1707..d6e7b94 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -26,7 +26,8 @@ jobs: commit-branch-check: name: "Check commit branch" runs-on: "ubuntu-latest" - needs: ["crate-info"] + needs: + - "crate-info" steps: - name: "Checkout source code" @@ -47,7 +48,8 @@ jobs: crate-version-check: name: "Check crate version" runs-on: "ubuntu-latest" - needs: ["crate-info"] + needs: + - "crate-info" steps: - name: "Checkout source code" @@ -65,39 +67,61 @@ jobs: draft-release: name: "Create draft release" runs-on: "ubuntu-latest" - needs: ["crate-info", "commit-branch-check", "crate-version-check"] + needs: + - "crate-info" + - "commit-branch-check" + - "crate-version-check" + outputs: + release-id: ${{ steps.create.outputs.id }} steps: - - name: "Create draft release" - uses: "softprops/action-gh-release@v1" - with: - generate_release_notes: true - draft: true + - id: "create" + name: "Create draft release" + run: | + ID=$(curl -L --fail "https://api.github.com/repos/${GITHUB_REPOSITORY}/releases" \ + -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ + -d '{"tag_name":"v${{ needs.crate-info.outputs.version }}","name":"v${{ needs.crate-info.outputs.version }}","draft":true,"generate_release_notes":true}' | + jq ".id") + echo "id=$ID" >> $GITHUB_OUTPUT release-non-apple: name: "Build for ${{ matrix.target }}" runs-on: "${{ matrix.os }}" - needs: ["crate-info", "commit-branch-check", "crate-version-check"] + needs: + - "crate-info" + - "draft-release" + - "commit-branch-check" + - "crate-version-check" strategy: matrix: include: - os: "ubuntu-latest" target: "x86_64-unknown-linux-gnu" + curl: "curl" exe: "starkli" + compressed_ext: "tar.gz" - os: "ubuntu-latest" target: "x86_64-unknown-linux-musl" + curl: "curl" exe: "starkli" + compressed_ext: "tar.gz" - os: "ubuntu-latest" target: "aarch64-unknown-linux-gnu" + curl: "curl" exe: "starkli" + compressed_ext: "tar.gz" - os: "ubuntu-latest" target: "aarch64-unknown-linux-musl" + curl: "curl" exe: "starkli" + compressed_ext: "tar.gz" - os: "windows-latest" target: "x86_64-pc-windows-msvc" + curl: "curl.exe" exe: "starkli.exe" + compressed_ext: "zip" steps: - name: "Checkout source code" @@ -139,26 +163,23 @@ jobs: directory: "target/${{ matrix.target }}/release/" path: "${{ matrix.exe }}" - - name: "Publish tar" - uses: "softprops/action-gh-release@v1" - if: matrix.os != 'windows-latest' - with: - files: "target/${{ matrix.target }}/release/starkli-${{ matrix.target }}.tar.gz" - generate_release_notes: true - draft: true + - name: "Publish compressed artifact" + run: | + ARTIFACT_NAME="starkli-${{ matrix.target }}.${{ matrix.compressed_ext }}" - - name: "Publish zip" - uses: "softprops/action-gh-release@v1" - if: matrix.os == 'windows-latest' - with: - files: "target/${{ matrix.target }}/release/starkli-${{ matrix.target }}.zip" - generate_release_notes: true - draft: true + ${{ matrix.curl }} -L --fail "https://uploads.github.com/repos/${GITHUB_REPOSITORY}/releases/${{ needs.draft-release.outputs.release-id }}/assets?name=${ARTIFACT_NAME}" \ + -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ + -H "Content-Type: application/octet-stream" \ + --data-binary "@target/${{ matrix.target }}/release/${ARTIFACT_NAME}" release-apple: name: "Build for ${{ matrix.target }}" runs-on: "${{ matrix.os }}" - needs: ["crate-info", "commit-branch-check", "crate-version-check"] + needs: + - "crate-info" + - "draft-release" + - "commit-branch-check" + - "crate-version-check" strategy: matrix: @@ -203,16 +224,23 @@ jobs: cd target/${{ matrix.target }}/release/ tar zcvf ./starkli-${{ matrix.target }}.tar.gz ./${{ matrix.exe }} - - name: "Publish tar" - uses: "softprops/action-gh-release@v1" - with: - files: "target/${{ matrix.target }}/release/starkli-${{ matrix.target }}.tar.gz" - generate_release_notes: true - draft: true + - name: "Publish compressed artifact" + run: | + ARTIFACT_NAME="starkli-${{ matrix.target }}.tar.gz" + + curl -L --fail "https://uploads.github.com/repos/${GITHUB_REPOSITORY}/releases/${{ needs.draft-release.outputs.release-id }}/assets?name=${ARTIFACT_NAME}" \ + -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ + -H "Content-Type: application/octet-stream" \ + --data-binary "@target/${{ matrix.target }}/release/${ARTIFACT_NAME}" release-android: name: "Build for aarch64-linux-android" runs-on: "ubuntu-latest" + needs: + - "crate-info" + - "draft-release" + - "commit-branch-check" + - "crate-version-check" steps: - name: "Checkout source code" @@ -267,9 +295,28 @@ jobs: cd target/aarch64-linux-android/release/ tar zcvf ./starkli-aarch64-linux-android.tar.gz ./starkli - - name: "Publish tar" - uses: "softprops/action-gh-release@v1" - with: - files: "target/aarch64-linux-android/release/starkli-aarch64-linux-android.tar.gz" - generate_release_notes: true - draft: true + - name: "Publish compressed artifact" + run: | + ARTIFACT_NAME="starkli-aarch64-linux-android.tar.gz" + + curl -L --fail "https://uploads.github.com/repos/${GITHUB_REPOSITORY}/releases/${{ needs.draft-release.outputs.release-id }}/assets?name=${ARTIFACT_NAME}" \ + -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ + -H "Content-Type: application/octet-stream" \ + --data-binary "@target/aarch64-linux-android/release/${ARTIFACT_NAME}" + + publish-release: + name: "Publish release" + runs-on: "ubuntu-latest" + needs: + - "draft-release" + - "release-non-apple" + - "release-apple" + - "release-android" + + steps: + - name: "Publish release" + run: | + curl -L --fail "https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/${{ needs.draft-release.outputs.release-id }}" \ + -X PATCH \ + -H "Authorization: Bearer ${{ secrets.GITHUB_ACTION }}" \ + -d '{"draft":false}'