|
1 |
| -name: release |
| 1 | +name: Release |
2 | 2 |
|
3 | 3 | on:
|
4 |
| - push: |
5 |
| - tags: |
6 |
| - - 'v*' |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + type: choice |
| 8 | + required: true |
| 9 | + description: 'Version number to bump' |
| 10 | + options: |
| 11 | + - patch |
| 12 | + - minor |
| 13 | + - major |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: write |
| 17 | + issues: write |
| 18 | + pull-requests: write |
7 | 19 |
|
8 | 20 | jobs:
|
9 |
| - create-release: |
10 |
| - name: Create Release |
| 21 | + publish-dry-run: |
| 22 | + name: "Runs cargo publish --dry-run" |
11 | 23 | runs-on: ubuntu-latest
|
12 | 24 | steps:
|
13 |
| - - name: Checkout source code |
14 |
| - uses: actions/checkout@v2 |
| 25 | + - uses: actions/checkout@v1 |
15 | 26 |
|
16 |
| - - name: Create Release Notes |
17 |
| - uses: actions/github-script@v5 |
| 27 | + - uses: actions-rs/toolchain@v1 |
18 | 28 | with:
|
19 |
| - github-token: ${{secrets.GITHUB_TOKEN}} |
20 |
| - script: | |
21 |
| - await github.request(`POST /repos/${{ github.repository }}/releases`, { |
22 |
| - tag_name: "${{ github.ref }}", |
23 |
| - generate_release_notes: true |
24 |
| - }); |
25 |
| -
|
26 |
| - build-artifacts: |
27 |
| - name: 'Build artifacts for ${{ matrix.os }}' |
28 |
| - runs-on: ${{ matrix.os }} |
29 |
| - needs: create-release |
30 |
| - strategy: |
31 |
| - matrix: |
32 |
| - name: |
33 |
| - - linux |
34 |
| - - macos |
35 |
| - - windows |
36 |
| - include: |
37 |
| - - name: linux |
38 |
| - os: ubuntu-latest |
39 |
| - artifact_name: 'http-server-linux' |
40 |
| - asset_name: 'http-server' |
41 |
| - asset_extension: '.tar.gz' |
| 29 | + profile: minimal |
| 30 | + toolchain: stable |
42 | 31 |
|
43 |
| - - name: macos |
44 |
| - os: macos-latest |
45 |
| - artifact_name: 'http-server-macos' |
46 |
| - asset_name: 'http-server' |
47 |
| - asset_extension: '.tar.gz' |
| 32 | + - name: publish crate |
| 33 | + run: cargo publish --dry-run |
48 | 34 |
|
49 |
| - - name: windows |
50 |
| - os: windows-latest |
51 |
| - artifact_name: 'http-server-windows.exe' |
52 |
| - asset_name: 'http-server.exe' |
53 |
| - asset_extension: '.zip' |
| 35 | + release: |
| 36 | + name: Create Release |
| 37 | + needs: publish-dry-run |
| 38 | + runs-on: ubuntu-latest |
54 | 39 | steps:
|
55 |
| - - name: Checkout source code |
| 40 | + - name: Checkout code |
56 | 41 | uses: actions/checkout@v2
|
57 | 42 |
|
58 |
| - - name: Setup environment variables |
59 |
| - shell: bash |
60 |
| - run: | |
61 |
| - RELEASE_VERSION=$(echo ${GITHUB_REF:10}) >> $GITHUB_ENV |
62 |
| -
|
63 |
| - - name: Setup Rust Toolchain |
| 43 | + - name: Setup Rust |
64 | 44 | uses: actions-rs/toolchain@v1
|
65 | 45 | with:
|
66 | 46 | profile: minimal
|
67 | 47 | toolchain: stable
|
| 48 | + override: true |
68 | 49 |
|
69 |
| - - name: Build optimized executable |
70 |
| - run: cargo build --release --locked |
| 50 | + - name: Install `cargo-edit` |
| 51 | + run: cargo install cargo-edit |
| 52 | + |
| 53 | + - id: cargo-set-version |
| 54 | + name: Set Version |
| 55 | + run: cargo set-version --bump ${{ inputs.version }} |
71 | 56 |
|
72 |
| - - name: Archive release assets |
73 |
| - shell: bash |
| 57 | + - name: Set Crate Version as Environment Variable |
74 | 58 | run: |
|
75 |
| - if [ "${{ matrix.os }}" = "windows-latest" ]; then |
76 |
| - cp target/release/http-server.exe ${{ matrix.asset_name }} |
77 |
| - else |
78 |
| - cp target/release/http-server "${{ matrix.asset_name }}" |
79 |
| - fi |
80 |
| -
|
81 |
| - - name: Attach builded binaries to release |
82 |
| - uses: svenstaro/upload-release-action@v1-release |
83 |
| - with: |
84 |
| - asset_name: 'http-server_${{ matrix.os }}' |
85 |
| - file: '${{ matrix.asset_name }}' |
86 |
| - repo_token: ${{ secrets.GITHUB_TOKEN }} |
87 |
| - tag: ${{ github.ref }} |
88 |
| - |
89 |
| - publish-crate: |
90 |
| - name: Publish to crates.io |
91 |
| - runs-on: ubuntu-latest |
92 |
| - needs: build-artifacts |
93 |
| - steps: |
94 |
| - - name: Checkout source code |
95 |
| - uses: actions/checkout@v2 |
| 59 | + CARGO_TOML_VERSION=$(awk -F ' = ' '$1 ~ /version/ { gsub(/[\"]/, "", $2); printf("%s",$2) }' Cargo.toml) |
| 60 | + echo "CRATE_VERSION=$CARGO_TOML_VERSION" >> $GITHUB_ENV |
96 | 61 |
|
97 |
| - - uses: actions-rs/toolchain@v1 |
98 |
| - with: |
99 |
| - profile: minimal |
100 |
| - toolchain: stable |
| 62 | + - name: Create Commit |
| 63 | + run: | |
| 64 | + git config --global user.name 'github-actions[bot]' |
| 65 | + git config --global user.email 'github-actions[bot]@users.noreply.github.com' |
| 66 | + git add . |
| 67 | + git commit -m "chore: bump version to v$CRATE_VERSION" |
| 68 | + git push origin main --follow-tags |
101 | 69 |
|
102 |
| - - run: cargo login ${CRATES_IO_TOKEN} |
| 70 | + - name: Login to Crates.io |
| 71 | + run: cargo login ${CRATES_IO_TOKEN} |
103 | 72 | env:
|
104 | 73 | CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
|
105 | 74 |
|
106 |
| - - name: publish crate |
| 75 | + - name: Publish crate |
107 | 76 | run: cargo publish
|
| 77 | + |
| 78 | + - name: Create Release |
| 79 | + id: create_release |
| 80 | + uses: actions/github-script@v5 |
| 81 | + with: |
| 82 | + script: | |
| 83 | + await github.request(`POST /repos/${{ github.repository }}/releases`, { |
| 84 | + tag_name: "v${{ env.CRATE_VERSION }}", |
| 85 | + generate_release_notes: true |
| 86 | + }); |
0 commit comments