Reduce workflow duplication

This commit is contained in:
Thomas Eizinger 2021-03-04 15:16:33 +11:00
parent 6ae8b63018
commit ab68b28fd8
No known key found for this signature in database
GPG Key ID: 651AC83A6C6C8B96
4 changed files with 35 additions and 166 deletions

View File

@ -1,38 +0,0 @@
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: gtar -C ./target/${{ inputs.target }}/release --create --file=${{ steps.create-archive-name.outputs.archive }} ${{ inputs.binary }}

View File

@ -1,38 +0,0 @@
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 }}

View File

@ -1,40 +0,0 @@
name: Create release archive
description: Creates a zip 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}.zip'
print(f'::set-output name=archive::{archive_name}')
- name: Make archive
shell: bash
run: |
cp -p ./target/${{ matrix.target }}/release/${{ inputs.binary }} ${{ inputs.binary }}.exe
7z a -tzip ${{ steps.create-archive-name.outputs.archive }} ${{ inputs.binary }}.exe

View File

@ -12,10 +12,13 @@ jobs:
include: include:
- target: x86_64-unknown-linux-gnu - target: x86_64-unknown-linux-gnu
os: ubuntu-latest os: ubuntu-latest
archive_ext: tar
- target: x86_64-apple-darwin - target: x86_64-apple-darwin
os: macos-latest os: macos-latest
archive_ext: tar
- target: x86_64-pc-windows-msvc - target: x86_64-pc-windows-msvc
os: windows-latest os: windows-latest
archive_ext: zip
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:
- name: Checkout tagged commit - name: Checkout tagged commit
@ -35,62 +38,44 @@ jobs:
with: with:
python-version: '3.x' python-version: '3.x'
- name: Create windows release archive - id: create-archive-name
id: create-archive-windows shell: python # Use python to have a prettier name for the archive on Windows.
if: contains(matrix.os, 'windows') run: |
uses: ./.github/actions/create-release-archive/windows import platform
with: os_info = platform.uname()
binary: swap_cli
version: ${{ github.event.release.tag_name }}
target: ${{ matrix.target }}
- name: Create macos release archive arch = os_info.machine
id: create-archive-macos
if: contains(matrix.os, 'macos')
uses: ./.github/actions/create-release-archive/macos
with:
binary: swap_cli
version: ${{ github.event.release.tag_name }}
target: ${{ matrix.target }}
- name: Create ubuntu release archive triple = "${{ matrix.target }}".split("-")
id: create-archive-ubuntu arch = triple[0]
if: contains(matrix.os, 'ubuntu')
uses: ./.github/actions/create-release-archive/ubuntu
with:
binary: swap_cli
version: ${{ github.event.release.tag_name }}
target: ${{ matrix.target }}
- name: Upload windows release binary archive_name=f'swap_cli_${{ github.event.release.tag_name }}_{os_info.system}_{arch}.${{ matrix.archive_ext }}'
if: contains(matrix.os, 'windows')
print(f'::set-output name=archive::{archive_name}')
- name: Pack macos archive
if: matrix.os == 'macos-latest'
shell: bash
run: gtar -C ./target/${{ matrix.target }}/release --create --file=${{ steps.create-archive-name.outputs.archive }} swap_cli
- name: Pack linux archive
if: matrix.os == 'ubuntu-latest'
shell: bash
run: tar -C ./target/${{ matrix.target }}/release --create --file=${{ steps.create-archive-name.outputs.archive }} swap_cli
- name: Pack windows archive
if: matrix.os == 'windows-latest'
shell: bash
run: |
cp target/${{ matrix.target }}/release/swap_cli.exe ./swap_cli.exe
7z a -tzip ${{ steps.create-archive-name.outputs.archive }} ./swap_cli.exe
- name: Upload archive
uses: actions/upload-release-asset@v1 uses: actions/upload-release-asset@v1
env: env:
GITHUB_TOKEN: ${{ secrets.BOTTY_GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.BOTTY_GITHUB_TOKEN }}
with: with:
upload_url: ${{ github.event.release.upload_url }} upload_url: ${{ github.event.release.upload_url }}
asset_path: ./${{ steps.create-archive-windows.outputs.archive }} asset_path: ./${{ steps.create-archive-name.outputs.archive }}
asset_name: ${{ steps.create-archive-windows.outputs.archive }} asset_name: ${{ steps.create-archive-name.outputs.archive }}
asset_content_type: application/gzip
- name: Upload macos release binary
if: contains(matrix.os, 'macos')
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-macos.outputs.archive }}
asset_name: ${{ steps.create-archive-macos.outputs.archive }}
asset_content_type: application/gzip
- name: Upload ubuntu release binary
if: contains(matrix.os, 'ubuntu')
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-ubuntu.outputs.archive }}
asset_name: ${{ steps.create-archive-ubuntu.outputs.archive }}
asset_content_type: application/gzip asset_content_type: application/gzip