Skip to content

Commit

Permalink
ci: automatically publish release
Browse files Browse the repository at this point in the history
  • Loading branch information
xJonathanLEI committed Aug 28, 2023
1 parent f111461 commit e461e0e
Showing 1 changed file with 83 additions and 36 deletions.
119 changes: 83 additions & 36 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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}'

0 comments on commit e461e0e

Please sign in to comment.