|
| 1 | +name: release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v[0-9]+.[0-9]+.[0-9]+' |
| 7 | + |
| 8 | +jobs: |
| 9 | + create_release: |
| 10 | + name: Create Release |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - name: Create artifacts directory |
| 14 | + run: mkdir artifacts |
| 15 | + |
| 16 | + - name: Get the release version from the tag |
| 17 | + if: env.RELEASE_VERSION == '' |
| 18 | + run: | |
| 19 | + echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV |
| 20 | + echo "version is: ${{ env.RELEASE_VERSION }}" |
| 21 | +
|
| 22 | + - name: Create GitHub release |
| 23 | + id: release |
| 24 | + uses: actions/create-release@v1 |
| 25 | + env: |
| 26 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 27 | + with: |
| 28 | + tag_name: ${{ env.RELEASE_VERSION }} |
| 29 | + release_name: ${{ env.RELEASE_VERSION }} |
| 30 | + draft: true |
| 31 | + |
| 32 | + - name: Save release upload URL to artifact |
| 33 | + run: echo "${{ steps.release.outputs.upload_url }}" > artifacts/release-upload-url |
| 34 | + |
| 35 | + - name: Save version number to artifact |
| 36 | + run: echo "${{ env.RELEASE_VERSION }}" > artifacts/release-version |
| 37 | + |
| 38 | + - name: Upload artifacts |
| 39 | + uses: actions/upload-artifact@v1 |
| 40 | + with: |
| 41 | + name: artifacts |
| 42 | + path: artifacts |
| 43 | + |
| 44 | + # cargo_publish: |
| 45 | + # name: Cargo Publish |
| 46 | + # needs: create_release |
| 47 | + # runs-on: ubuntu-latest |
| 48 | + # steps: |
| 49 | + # - uses: actions/checkout@v2 |
| 50 | + # - name: Cargo login |
| 51 | + # run: cargo login ${CRATES_IO_TOKEN} |
| 52 | + # env: |
| 53 | + # CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }} |
| 54 | + # - run: cargo publish |
| 55 | + |
| 56 | + build_release: |
| 57 | + name: Build Release |
| 58 | + needs: create_release |
| 59 | + runs-on: ${{ matrix.os }} |
| 60 | + env: |
| 61 | + CARGO: cargo |
| 62 | + RUSTFLAGS: -C strip=symbols |
| 63 | + TARGET_FLAGS: --target ${{ matrix.target }} |
| 64 | + TARGET_DIR: ./target/${{ matrix.target }} |
| 65 | + RUST_BACKTRACE: 1 |
| 66 | + strategy: |
| 67 | + matrix: |
| 68 | + build: [linux, linux-armv7, linux-aarch64, macos] |
| 69 | + include: |
| 70 | + - build: linux |
| 71 | + os: ubuntu-18.04 |
| 72 | + rust: stable |
| 73 | + target: x86_64-unknown-linux-musl |
| 74 | + strip: strip |
| 75 | + - build: linux-armv7 |
| 76 | + os: ubuntu-18.04 |
| 77 | + rust: stable |
| 78 | + target: armv7-unknown-linux-gnueabihf |
| 79 | + strip: arm-linux-gnueabihf-strip |
| 80 | + - build: linux-aarch64 |
| 81 | + os: ubuntu-18.04 |
| 82 | + rust: stable |
| 83 | + target: aarch64-unknown-linux-musl |
| 84 | + strip: aarch64-linux-musl-strip |
| 85 | + - build: macos |
| 86 | + os: macOS-latest |
| 87 | + rust: stable |
| 88 | + target: x86_64-apple-darwin |
| 89 | + strip: strip |
| 90 | + # - build: macos-aarch64 |
| 91 | + # os: macOS-latest |
| 92 | + # rust: stable |
| 93 | + # target: aarch64-apple-darwin |
| 94 | + # strip: strip |
| 95 | + |
| 96 | + steps: |
| 97 | + - name: Checkout repository |
| 98 | + uses: actions/checkout@v2 |
| 99 | + with: |
| 100 | + fetch-depth: 1 |
| 101 | + |
| 102 | + - name: Install packages (Ubuntu) |
| 103 | + if: matrix.os == 'ubuntu-18.04' |
| 104 | + run: sudo apt install libssl-dev zlib1g-dev |
| 105 | + |
| 106 | + - name: Install Rust |
| 107 | + uses: actions-rs/toolchain@v1 |
| 108 | + with: |
| 109 | + toolchain: ${{ matrix.rust }} |
| 110 | + profile: minimal |
| 111 | + override: true |
| 112 | + target: ${{ matrix.target }} |
| 113 | + |
| 114 | + - name: Use Cross |
| 115 | + if: matrix.build == 'linux-armv7' || matrix.build == 'linux-aarch64' |
| 116 | + run: | |
| 117 | + cargo install cross |
| 118 | + echo "CARGO=cross" >> $GITHUB_ENV |
| 119 | +
|
| 120 | + - name: Get release download URL |
| 121 | + uses: actions/download-artifact@v1 |
| 122 | + with: |
| 123 | + name: artifacts |
| 124 | + path: artifacts |
| 125 | + |
| 126 | + - name: Set release upload URL and release version |
| 127 | + shell: bash |
| 128 | + run: | |
| 129 | + release_upload_url="$(cat artifacts/release-upload-url)" |
| 130 | + echo "RELEASE_UPLOAD_URL=$release_upload_url" >> $GITHUB_ENV |
| 131 | + echo "release upload url: $RELEASE_UPLOAD_URL" |
| 132 | + release_version="$(cat artifacts/release-version)" |
| 133 | + echo "RELEASE_VERSION=$release_version" >> $GITHUB_ENV |
| 134 | + echo "release version: $RELEASE_VERSION" |
| 135 | +
|
| 136 | + - name: Build release binary |
| 137 | + run: RUSTFLAGS="${{ env.RUSTFLAGS }}" ${{ env.CARGO }} build ${{ env.TARGET_FLAGS }} --verbose --release |
| 138 | + |
| 139 | + - name: Strip release binary (arm) |
| 140 | + if: matrix.build == 'linux-armv7' || matrix.build == 'linux-aarch64' |
| 141 | + run: | |
| 142 | + docker run --rm -v \ |
| 143 | + "$PWD/target:/target:Z" \ |
| 144 | + rustembedded/cross:${{ matrix.target }} \ |
| 145 | + ${{ matrix.strip }} \ |
| 146 | + /target/${{ matrix.target }}/release/phpup |
| 147 | +
|
| 148 | + - name: Build archive |
| 149 | + shell: bash |
| 150 | + run: | |
| 151 | + staging="phpup-${{ env.RELEASE_VERSION }}-${{ matrix.build }}" |
| 152 | + mkdir "$staging" |
| 153 | + cp {README.md,LICENSE} "$staging/" |
| 154 | + cp "target/${{ matrix.target }}/release/phpup" "$staging/" |
| 155 | + zip -r "$staging.zip" "$staging" |
| 156 | + echo "ASSET=$staging.zip" >> $GITHUB_ENV |
| 157 | +
|
| 158 | + - name: Upload release archive |
| 159 | + uses: actions/upload-release-asset@v1.0.1 |
| 160 | + env: |
| 161 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 162 | + with: |
| 163 | + upload_url: ${{ env.RELEASE_UPLOAD_URL }} |
| 164 | + asset_path: ${{ env.ASSET }} |
| 165 | + asset_name: ${{ env.ASSET }} |
| 166 | + asset_content_type: application/octet-stream |
0 commit comments