|
1 | | -name: Build and Release App |
| 1 | +name: Release |
2 | 2 |
|
3 | 3 | on: |
| 4 | + push: |
| 5 | + branches: [ main ] |
4 | 6 | workflow_dispatch: |
5 | 7 |
|
6 | 8 | permissions: |
7 | 9 | contents: write |
| 10 | + pull-requests: write |
8 | 11 |
|
9 | 12 | concurrency: |
10 | 13 | group: release-${{ github.ref }} |
11 | 14 | cancel-in-progress: true |
12 | 15 |
|
13 | 16 | jobs: |
14 | | - version: |
| 17 | + release-please: |
15 | 18 | runs-on: ubuntu-latest |
16 | 19 | outputs: |
17 | | - version: ${{ steps.v.outputs.version }} |
| 20 | + released: ${{ steps.release.outputs.release_created }} |
| 21 | + tag: ${{ steps.release.outputs.tag_name }} |
18 | 22 | steps: |
19 | | - - uses: actions/checkout@v4 |
20 | | - - id: v |
21 | | - run: | |
22 | | - V=$(grep '^version' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/') |
23 | | - echo "version=$V" >> $GITHUB_OUTPUT |
24 | | -
|
25 | | - changelog: |
26 | | - runs-on: ubuntu-latest |
27 | | - steps: |
28 | | - - uses: actions/checkout@v4 |
| 23 | + - uses: googleapis/release-please-action@v4 |
| 24 | + id: release |
29 | 25 | with: |
30 | | - fetch-depth: 0 |
31 | | - |
32 | | - - name: Install git-cliff |
33 | | - run: | |
34 | | - VERSION=$(gh release view --repo orhun/git-cliff --json tagName -q .tagName) |
35 | | - curl -sL "https://github.com/orhun/git-cliff/releases/download/${VERSION}/git-cliff-${VERSION}-x86_64-unknown-linux-gnu.tar.gz" | tar -xz |
36 | | - sudo mv git-cliff /usr/local/bin/ |
37 | | - env: |
38 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
39 | | - |
40 | | - - name: Generate changelog |
41 | | - run: git-cliff -o CHANGELOG.md |
42 | | - |
43 | | - - uses: actions/upload-artifact@v4 |
44 | | - with: |
45 | | - name: changelog |
46 | | - path: CHANGELOG.md |
| 26 | + config-file: .github/release-please-config.json |
47 | 27 |
|
48 | 28 | build: |
49 | | - needs: version |
| 29 | + needs: release-please |
| 30 | + if: needs.release-please.outputs.released == 'true' |
50 | 31 | strategy: |
51 | 32 | matrix: |
52 | 33 | include: |
53 | 34 | - os: ubuntu-latest |
54 | 35 | target: x86_64-unknown-linux-gnu |
55 | 36 | bin: pyelevate |
56 | | - osname: linux |
57 | 37 | ext: "" |
58 | | - pack: tar |
| 38 | + archive: tar.gz |
| 39 | + |
59 | 40 | - os: windows-latest |
60 | 41 | target: x86_64-pc-windows-msvc |
61 | 42 | bin: pyelevate.exe |
62 | | - osname: windows |
63 | 43 | ext: ".exe" |
64 | | - pack: zip |
| 44 | + archive: zip |
| 45 | + |
65 | 46 | - os: macos-latest |
66 | 47 | target: aarch64-apple-darwin |
67 | 48 | bin: pyelevate |
68 | | - osname: macos-arm64 |
69 | 49 | ext: "" |
70 | | - pack: tar |
| 50 | + archive: tar.gz |
71 | 51 |
|
72 | 52 | runs-on: ${{ matrix.os }} |
73 | 53 |
|
74 | 54 | steps: |
75 | 55 | - uses: actions/checkout@v4 |
| 56 | + |
76 | 57 | - uses: dtolnay/rust-toolchain@stable |
| 58 | + |
77 | 59 | - uses: Swatinem/rust-cache@v2 |
78 | 60 |
|
79 | 61 | - run: rustup target add ${{ matrix.target }} |
80 | | - - run: cargo build --release --target ${{ matrix.target }} |
81 | 62 |
|
82 | | - - name: Ensure zip exists |
83 | | - if: matrix.os == 'windows-latest' |
84 | | - run: choco install zip -y |
| 63 | + - run: cargo build --release --target ${{ matrix.target }} |
85 | 64 |
|
86 | 65 | - name: Package |
87 | 66 | shell: bash |
88 | 67 | run: | |
89 | | - NAME=pyelevate-v${{ needs.version.outputs.version }}-${{ matrix.osname }} |
90 | | - mkdir pkg |
91 | | - cp target/${{ matrix.target }}/release/${{ matrix.bin }} pkg/pyelevate${{ matrix.ext }} |
| 68 | + VERSION=${{ needs.release-please.outputs.tag }} |
| 69 | + NAME=pyelevate-${VERSION}-${{ matrix.target }} |
92 | 70 |
|
93 | | - if [ "${{ matrix.pack }}" = "zip" ]; then |
94 | | - cd pkg && zip -9 ../$NAME.zip * |
| 71 | + mkdir dist |
| 72 | + cp target/${{ matrix.target }}/release/${{ matrix.bin }} dist/ |
| 73 | +
|
| 74 | + cd dist |
| 75 | +
|
| 76 | + if [ "${{ matrix.archive }}" = "zip" ]; then |
| 77 | + powershell Compress-Archive -Path * -DestinationPath ../$NAME.zip |
95 | 78 | else |
96 | | - tar -C pkg -cJf $NAME.tar.xz . |
| 79 | + tar -czf ../$NAME.tar.gz * |
97 | 80 | fi |
98 | 81 |
|
| 82 | + cd .. |
99 | 83 | sha256sum $NAME.* > $NAME.sha256 |
100 | 84 |
|
101 | | - - uses: actions/upload-artifact@v4 |
| 85 | + - uses: softprops/action-gh-release@v2 |
102 | 86 | with: |
103 | | - name: ${{ matrix.osname }} |
104 | | - path: | |
| 87 | + tag_name: ${{ needs.release-please.outputs.tag }} |
| 88 | + files: | |
105 | 89 | *.zip |
106 | | - *.tar.xz |
| 90 | + *.tar.gz |
107 | 91 | *.sha256 |
108 | | -
|
109 | | - release: |
110 | | - needs: [version, build, changelog] |
111 | | - runs-on: ubuntu-latest |
112 | | - |
113 | | - steps: |
114 | | - - uses: actions/download-artifact@v4 |
115 | | - with: |
116 | | - path: artifacts |
117 | | - |
118 | | - - uses: softprops/action-gh-release@v2 |
119 | | - with: |
120 | | - tag_name: v${{ needs.version.outputs.version }} |
121 | | - name: PyElevate v${{ needs.version.outputs.version }} |
122 | | - body_path: artifacts/changelog/CHANGELOG.md |
123 | | - files: artifacts/**/* |
124 | 92 | env: |
125 | 93 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments