|
| 1 | +name: publish-packge-on-github-release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + |
| 8 | +jobs: |
| 9 | + create-release: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - name: Create Release |
| 13 | + id: create-release |
| 14 | + uses: actions/create-release@v1 |
| 15 | + env: |
| 16 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 17 | + with: |
| 18 | + tag_name: ${{ github.ref }} |
| 19 | + release_name: Release ${{ github.ref }} |
| 20 | + draft: false |
| 21 | + prerelease: false |
| 22 | + - name: Save upload URL |
| 23 | + run: echo "${{ steps.create-release.outputs.upload_url }}" > upload-url.txt |
| 24 | + - uses: actions/upload-artifact@v1 |
| 25 | + with: |
| 26 | + name: upload-url |
| 27 | + path: upload-url.txt |
| 28 | + |
| 29 | + build-and-test: |
| 30 | + needs: create-release |
| 31 | + runs-on: ${{ matrix.os }} |
| 32 | + strategy: |
| 33 | + matrix: |
| 34 | + os: |
| 35 | + - ubuntu-latest |
| 36 | + - macOS-latest |
| 37 | + - windows-latest |
| 38 | + steps: |
| 39 | + - name: Install gnu tools on macOS |
| 40 | + run: | |
| 41 | + brew install gnu-tar |
| 42 | + echo 'export PATH="/usr/local/opt/gnu-tar/libexec/gnubin:$PATH"' >> ~/.bash_profile |
| 43 | + if: matrix.os == 'macOS-latest' |
| 44 | + |
| 45 | + - uses: actions/checkout@v2 |
| 46 | + |
| 47 | + - name: Restore upload URL from artifact |
| 48 | + uses: actions/download-artifact@v1 |
| 49 | + with: |
| 50 | + name: upload-url |
| 51 | + - run: echo "##[set-output name=url;]$(cat upload-url/upload-url.txt)" |
| 52 | + id: upload-url |
| 53 | + |
| 54 | + - uses: actions-rs/toolchain@v1 |
| 55 | + with: |
| 56 | + toolchain: stable |
| 57 | + override: true |
| 58 | + - name: Get current LLVM target |
| 59 | + run: echo "##[set-output name=target;]$(rustc --version -v | grep host | cut -d ' ' -f 2)" |
| 60 | + id: current-target |
| 61 | + |
| 62 | + - name: Test all |
| 63 | + uses: actions-rs/cargo@v1 |
| 64 | + with: |
| 65 | + command: test |
| 66 | + args: --all-features --no-fail-fast |
| 67 | + - name: Build for release |
| 68 | + uses: actions-rs/cargo@v1 |
| 69 | + with: |
| 70 | + command: build |
| 71 | + args: --release |
| 72 | + |
| 73 | + - name: Create tar archive on Linux and macOS |
| 74 | + shell: bash -l {0} |
| 75 | + run: | |
| 76 | + echo ${CURRENT_TARGET} |
| 77 | + tar cvzf openssh-authorizedkeyscommand-github.${CURRENT_TARGET}.tar.gz --owner=0 --group=0 -C target/release/ openssh-authorizedkeyscommand-github |
| 78 | + if: matrix.os != 'windows-latest' |
| 79 | + env: |
| 80 | + CURRENT_TARGET: ${{ steps.current-target.outputs.target }} |
| 81 | + |
| 82 | + - name: Create zip archive on Windows |
| 83 | + shell: pwsh |
| 84 | + run: | |
| 85 | + cd target/release/ |
| 86 | + Compress-Archive -Path openssh-authorizedkeyscommand-github.exe -DestinationPath ../../openssh-authorizedkeyscommand-github.${env:CURRENT_TARGET}.zip |
| 87 | + dir |
| 88 | + if: matrix.os == 'windows-latest' |
| 89 | + env: |
| 90 | + CURRENT_TARGET: ${{ steps.current-target.outputs.target }} |
| 91 | + |
| 92 | + - name: Upload Release Asset for Linux and macOS |
| 93 | + uses: actions/upload-release-asset@v1 |
| 94 | + if: matrix.os != 'windows-latest' |
| 95 | + env: |
| 96 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 97 | + with: |
| 98 | + upload_url: ${{ steps.upload-url.outputs.url }} |
| 99 | + asset_path: openssh-authorizedkeyscommand-github.${{ steps.current-target.outputs.target }}.tar.gz |
| 100 | + asset_name: openssh-authorizedkeyscommand-github.${{ steps.current-target.outputs.target }}.tar.gz |
| 101 | + asset_content_type: application/gzip |
| 102 | + - name: Upload Release Asset for Windows |
| 103 | + uses: actions/upload-release-asset@v1 |
| 104 | + if: matrix.os == 'windows-latest' |
| 105 | + env: |
| 106 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 107 | + CURRENT_TARGET: ${{ steps.current-target.outputs.target }} |
| 108 | + with: |
| 109 | + upload_url: ${{ steps.upload-url.outputs.url }} |
| 110 | + asset_path: openssh-authorizedkeyscommand-github.${{ steps.current-target.outputs.target }}.zip |
| 111 | + asset_name: openssh-authorizedkeyscommand-github.${{ steps.current-target.outputs.target }}.zip |
| 112 | + asset_content_type: application/zip |
0 commit comments