name: release on: push: tags: - 'v[0-9]+.[0-9]+.[0-9]+' jobs: create-release: name: create-release runs-on: ubuntu-latest steps: - name: Create artifacts directory run: mkdir artifacts - name: Get the release version from the tag if: env.VERSION == '' run: | echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV echo "version is: ${{ env.VERSION }}" - name: Create GitHub release id: release uses: actions/create-release@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: tag_name: ${{ env.VERSION }} release_name: ${{ env.VERSION }} - name: Save release upload URL to artifact run: echo "${{ steps.release.outputs.upload_url }}" > artifacts/release-upload-url - name: Save version number to artifact run: echo "${{ env.VERSION }}" > artifacts/release-version - name: Upload artifacts uses: actions/upload-artifact@v1 with: name: artifacts path: artifacts build-release: name: build-release needs: [ 'create-release' ] runs-on: ${{ matrix.os }} env: # Emit backtraces on panics. RUST_BACKTRACE: 1 strategy: matrix: build: [ linux-amd64, macos-intel, windows ] include: - build: linux-amd64 os: ubuntu-18.04 rust: stable target: x86_64-unknown-linux-musl - build: macos-intel os: macos-latest rust: stable target: x86_64-apple-darwin - build: windows os: windows-2019 rust: stable target: x86_64-pc-windows-msvc steps: - name: Checkout repository uses: actions/checkout@v2 with: fetch-depth: 1 - name: Install packages (Ubuntu) if: matrix.os == 'ubuntu-18.04' run: | .github/ci/ubuntu-install-packages - name: Install packages (macOS) if: matrix.os == 'macos-latest' run: | .github/ci/macos-install-packages - name: Install Rust uses: actions-rs/toolchain@v1 with: toolchain: ${{ matrix.rust }} profile: minimal override: true target: ${{ matrix.target }} - name: Get release download URL uses: actions/download-artifact@v1 with: name: artifacts path: artifacts - name: Set release upload URL shell: bash run: | release_upload_url="$(cat artifacts/release-upload-url)" echo "RELEASE_UPLOAD_URL=$release_upload_url" >> $GITHUB_ENV echo "release upload url: $release_upload_url" - name: Build onetun binary run: cargo build --release - name: Prepare onetun binary shell: bash run: | mkdir -p ci/assets if [ "${{ matrix.build }}" = "windows" ]; then cp "target/release/onetun.exe" "ci/assets/onetun.exe" echo "ASSET=onetun.exe" >> $GITHUB_ENV else cp "target/release/onetun" "ci/assets/onetun-${{ matrix.build }}" echo "ASSET=onetun-${{ matrix.build }}" >> $GITHUB_ENV fi - name: Upload release archive uses: actions/upload-release-asset@v1.0.1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ env.RELEASE_UPLOAD_URL }} asset_path: ci/assets/${{ env.ASSET }} asset_name: ${{ env.ASSET }} asset_content_type: application/octet-stream