From c5376fc1205d57561ac5e15620df4e5799465a5c Mon Sep 17 00:00:00 2001 From: Eric Prestat Date: Fri, 3 May 2024 20:51:30 +0100 Subject: [PATCH] Don't hardcore organisation in reusable workflow (make it an optional parameter) --- .github/workflows/doc.yml | 9 ++++++--- .github/workflows/package_and_test.yml | 9 ++++++--- .github/workflows/release_pure_python.yml | 15 ++++++++++++--- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/.github/workflows/doc.yml b/.github/workflows/doc.yml index 75f423d..87119e6 100644 --- a/.github/workflows/doc.yml +++ b/.github/workflows/doc.yml @@ -40,7 +40,10 @@ on: description: 'Whether to check the links in the documentation' default: true type: boolean - + ORGANISATION: + description: 'The organisation hosting the upstream code' + default: 'hyperspy' + type: string jobs: build: @@ -58,11 +61,11 @@ jobs: echo "REPOSITORY_NAME=${GITHUB_REPOSITORY#*/}" >> $GITHUB_ENV - name: Fetch tags upstream - if: ${{ github.repository_owner != 'hyperspy' }} + if: ${{ github.repository_owner != inputs.ORGANISATION }} # Needs to fetch the tags from upstream to get the # correct version with setuptools_scm run: | - git remote add upstream https://github.com/hyperspy/${{env.REPOSITORY_NAME}}.git + git remote add upstream https://github.com/${{ inputs.ORGANISATION }}/${{ env.REPOSITORY_NAME }}.git git fetch upstream --tags - name: Install package in Ubuntu diff --git a/.github/workflows/package_and_test.yml b/.github/workflows/package_and_test.yml index e258b66..d787a6b 100644 --- a/.github/workflows/package_and_test.yml +++ b/.github/workflows/package_and_test.yml @@ -38,7 +38,10 @@ on: # if empty string, no argument is passed default: '' type: string - + ORGANISATION: + description: 'The organisation hosting the upstream code' + default: 'hyperspy' + type: string env: PYTHON_VERSION: '3.11' @@ -58,11 +61,11 @@ jobs: run: echo "REPOSITORY_NAME=${GITHUB_REPOSITORY#*/}" >> $GITHUB_ENV - name: Fetch tags upstream - if: ${{ github.repository_owner != 'hyperspy' }} + if: ${{ github.repository_owner != inputs.ORGANISATION }} # Needs to fetch the tags from upstream to get the # correct version with setuptools_scm run: | - git remote add upstream https://github.com/hyperspy/${{ env.REPOSITORY_NAME }}.git + git remote add upstream https://github.com/${{ inputs.ORGANISATION }}/${{ env.REPOSITORY_NAME }}.git git fetch upstream --tags - uses: actions/setup-python@v5 diff --git a/.github/workflows/release_pure_python.yml b/.github/workflows/release_pure_python.yml index 8079007..9295a53 100644 --- a/.github/workflows/release_pure_python.yml +++ b/.github/workflows/release_pure_python.yml @@ -1,7 +1,16 @@ +# This workflow can't be used as reusable workflow because it is +# concurrently not compatible with trusted publisher +# https://github.com/pypa/gh-action-pypi-publish/issues/166 + name: Release on: - workflow_call + workflow_call: + inputs: + ORGANISATION: + description: 'The organisation hosting the upstream code' + default: 'hyperspy' + type: string jobs: package_and_test: @@ -26,7 +35,7 @@ jobs: working-directory: dist - uses: pypa/gh-action-pypi-publish@release/v1 - if: ${{ startsWith(github.ref, 'refs/tags/') && github.repository_owner == 'hyperspy' }} + if: ${{ startsWith(github.ref, 'refs/tags/') && github.repository_owner == inputs.ORGANISATION }} # See https://docs.pypi.org/trusted-publishers/using-a-publisher/ create_github_release: @@ -41,5 +50,5 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - name: Create Release - if: ${{ startsWith(github.ref, 'refs/tags/') && github.repository_owner == 'hyperspy' }} + if: ${{ startsWith(github.ref, 'refs/tags/') && github.repository_owner == inputs.ORGANISATION }} uses: softprops/action-gh-release@9d7c94cfd0a1f3ed45544c887983e9fa900f0564