diff --git a/.github/actions/create-release-archive/action.yml b/.github/actions/create-release-archive/action.yml new file mode 100644 index 00000000..45934d0d --- /dev/null +++ b/.github/actions/create-release-archive/action.yml @@ -0,0 +1,38 @@ +name: Create release archive +description: Creates a tar archive for a release binary +inputs: + version: + description: 'The version of the binary' + required: true + binary: + description: 'The name of the binary to pack into the archive' + required: true + target: + description: 'The target triple, used to find the binary; pass it if the compilation was done with the `--target` argument' + required: false +outputs: + archive: + description: 'The name of the archive' + value: ${{ steps.create-archive-name.outputs.archive }} +runs: + using: "composite" + steps: + - id: create-archive-name + shell: python # Use python to have a prettier name for the archive on Windows. + run: | + import platform + os_info = platform.uname() + + arch = os_info.machine + + if "${{ inputs.target }}": + triple = "${{ inputs.target }}".split("-") + arch = triple[0] + + archive_name=f'${{ inputs.binary }}_${{ inputs.version }}_{os_info.system}_{arch}.tar' + + print(f'::set-output name=archive::{archive_name}') + + - name: Make archive + shell: bash + run: tar -C ./target/${{ inputs.target }}/release --create --file=${{ steps.create-archive-name.outputs.archive }} ${{ inputs.binary }} \ No newline at end of file diff --git a/.github/workflows/release-cli.yml b/.github/workflows/release-cli.yml new file mode 100644 index 00000000..2a886ade --- /dev/null +++ b/.github/workflows/release-cli.yml @@ -0,0 +1,51 @@ +name: "Release swap_cli" + +on: + release: + types: [created] + +jobs: + release: + name: Release swap_cli + strategy: + matrix: + include: + - target: x86_64-unknown-linux-gnu + os: ubuntu-latest + - target: x86_64-apple-darwin + os: macos-latest + - target: x86_64-pc-windows-msvc + os: windows-latest + runs-on: ${{ matrix.os }} + steps: + - name: Checkout tagged commit + uses: actions/checkout@v2 + with: + ref: ${{ github.event.release.target_commitish }} + token: ${{ secrets.BOTTY_GITHUB_TOKEN }} + + - name: Build ${{ matrix.target }} release binary + run: cargo build --target=${{ matrix.target }} --release --package swap --bin swap_cli + + # Remove once python 3 is the default + - uses: actions/setup-python@v1 + with: + python-version: '3.x' + + - name: Create release archive + id: create-archive + uses: ./.github/actions/create-release-archive + with: + binary: swap_cli + version: ${{ github.event.release.tag_name }} + target: ${{ matrix.target }} + + - name: Upload ${{ matrix.os }} release binary + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.BOTTY_GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: ./${{ steps.create-archive.outputs.archive }} + asset_name: ${{ steps.create-archive.outputs.archive }} + asset_content_type: application/gzip \ No newline at end of file