Skip to content

Commit

Permalink
Add a workflow to parse the version
Browse files Browse the repository at this point in the history
  • Loading branch information
FirelightFlagboy committed Mar 4, 2024
1 parent 69b3bba commit dbd4783
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 89 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/_parse_version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Parse Version

on:
workflow_call:
inputs:
version:
required: true
type: string
description: The version to parse
outputs:
full:
description: The full version
value: ${{ jobs.parse.outputs.full }}
pep440:
description: The PEP 440 version
value: ${{ jobs.parse.outputs.pep440 }}
major:
description: The major version
value: ${{ jobs.parse.outputs.major }}
minor:
description: The minor version
value: ${{ jobs.parse.outputs.minor }}
patch:
description: The patch version
value: ${{ jobs.parse.outputs.patch }}
pre:
description: The pre-release version
value: ${{ jobs.parse.outputs.pre }}
dev:
description: The dev version
value: ${{ jobs.parse.outputs.dev }}
local:
description: The local version
value: ${{ jobs.parse.outputs.local }}

jobs:
parse:
name: Parse Version
runs-on: ubuntu-22.04
outputs:
full: ${{ steps.version.outputs.full }}
pep440: ${{ steps.version.outputs.pep440 }}
major: ${{ steps.version.outputs.major }}
minor: ${{ steps.version.outputs.minor }}
patch: ${{ steps.version.outputs.patch }}
pre: ${{ steps.version.outputs.prerelease }}
dev: ${{ steps.version.outputs.dev }}
local: ${{ steps.version.outputs.local }}
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # pin v4.1.1
timeout-minutes: 5

- name: Parse Version
id: version
shell: bash
run: >-
PYTHONPATH=. python3
misc/releaser.py version
"${{ inputs.version || '--uniq-dev' }}"
| tee -a "$GITHUB_OUTPUT"
timeout-minutes: 2
46 changes: 9 additions & 37 deletions .github/workflows/package-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ permissions:
contents: read

jobs:
version:
uses: ./.github/workflows/_parse_version.yml
with:
version: ${{ inputs.version }}

package-wheel:
needs: version
strategy:
fail-fast: false
matrix:
Expand All @@ -54,8 +60,6 @@ jobs:
os: windows-2022
name: "${{ matrix.name }}: 📦 Packaging (build Wheel)"
runs-on: ${{ matrix.os }}
outputs:
wheel-version: ${{ steps.version.outputs.full }}
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # pin v4.1.1
timeout-minutes: 5
Expand All @@ -66,40 +70,8 @@ jobs:
project-path: ./server
timeout-minutes: 10

- name: Get wheel version
id: version
shell: bash
run: |
set -eux
function parse_version {
PYTHONPATH=. python3 misc/releaser.py version "$@"
}
if [ -n "${{ inputs.version }}" ]; then
parse_version "${{ inputs.version }}" | tee -a $GITHUB_OUTPUT
else
case "${{ github.event_name }}" in
workflow_call)
echo "The top workflow should have provided the version to use"
exit 2
;;
workflow_dispatch)
# No version provided, fallback to the version in the repository
parse_version --uniq-dev | tee -a $GITHUB_OUTPUT
;;
pull_request)
parse_version --uniq-dev | tee -a $GITHUB_OUTPUT
;;
*)
echo 'Unsupported event type ${{ github.event_name }}' >&2
exit 1
;;
esac
fi
- name: Set parsec version ${{ steps.version.outputs.full }}
run: python3 misc/version_updater.py --tool parsec --version ${{ steps.version.outputs.full }}
- name: Set parsec version ${{ needs.version.outputs.full }}
run: python3 misc/version_updater.py --tool parsec --version ${{ needs.version.outputs.full }}

- name: Build wheel
uses: pypa/cibuildwheel@ce3fb7832089eb3e723a0a99cab7f3eaccf074fd # pin v2.16.5
Expand All @@ -109,7 +81,7 @@ jobs:
timeout-minutes: 50

- name: Set file for wheel version
run: echo ${{ steps.version.outputs.full }} > dist/version
run: echo ${{ needs.version.outputs.full }} > dist/version

- name: Hack the wheel macos version
if: startsWith(matrix.os, 'macos-')
Expand Down
62 changes: 10 additions & 52 deletions .github/workflows/releaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,56 +20,14 @@ concurrency:

jobs:
version:
runs-on: ubuntu-22.04
outputs:
full: ${{ steps.version.outputs.full }}
pep440: ${{ steps.version.outputs.pep440 }}
major: ${{ steps.version.outputs.major }}
minor: ${{ steps.version.outputs.minor }}
patch: ${{ steps.version.outputs.patch }}
prerelease: ${{ steps.version.outputs.prerelease }}
dev: ${{ steps.version.outputs.dev }}
local: ${{ steps.version.outputs.local }}
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # pin v4.1.1
timeout-minutes: 5

- name: Parse version for event ${{ github.event_name }}
id: version
run: |
set -o pipefail
function parse_version {
PYTHONPATH=. python3 misc/releaser.py version "$@"
}
case "${{ github.event_name }}" in
push)
echo "Triggered by a Push"
parse_version "${{ github.ref_name }}" | tee -a $GITHUB_OUTPUT
;;
workflow_dispatch)
# If workflow dispatch trigger from a tag, we use the tag as a version else we behave like pull_request
TAG="${{ startsWith(github.ref, 'refs/tags/') && github.ref_name || '' }}"
# If TAG isn't empty use it.
if [ -n $TAG ]; then
parse_version $TAG | tee -a $GITHUB_OUTPUT
else
parse_version --uniq-dev | tee -a $GITHUB_OUTPUT
fi
;;
pull_request)
echo "Triggered by a Pull-Request"
parse_version --uniq-dev | tee -a $GITHUB_OUTPUT
;;
*)
echo "Unsupported event type ${{ github.event_name }}" >&2
exit 1
;;
esac
uses: ./.github/workflows/_parse_version.yml
with:
version: >-
${{
github.event_name == 'push' && github.ref_name ||
startsWith(github.ref, 'refs/tags/') && github.ref_name ||
''
}}
package-parsec-server:
needs:
Expand Down Expand Up @@ -117,7 +75,7 @@ jobs:
echo "major=${{ needs.version.outputs.major }}";
echo "minor=${{ needs.version.outputs.minor }}";
echo "patch=${{ needs.version.outputs.patch }}";
echo "prerelease=${{ needs.version.outputs.prerelease }}";
echo "pre=${{ needs.version.outputs.pre }}";
echo "dev=${{ needs.version.outputs.dev }}";
echo "local=${{ needs.version.outputs.local }}";
) | tee release-files/version
Expand Down Expand Up @@ -162,7 +120,7 @@ jobs:
with:
draft: true
body: ${{ steps.summary.outputs.output }}
prerelease: ${{ needs.version.outputs.prerelease != '' || needs.version.outputs.dev != '' || needs.version.outputs.local != '' }}
prerelease: ${{ needs.version.outputs.pre != '' || needs.version.outputs.dev != '' || needs.version.outputs.local != '' }}
name: Release v${{ needs.version.outputs.full }}
tag_name: v${{ needs.version.outputs.full }}
files: |
Expand Down

0 comments on commit dbd4783

Please sign in to comment.