Skip to content

Fix release workflow #200

Fix release workflow

Fix release workflow #200

Workflow file for this run

# This file is part of tad-dftd4.
#
# SPDX-Identifier: Apache-2.0
# Copyright (C) 2024 Grimme Group
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Build
on:
push:
branches:
- main
- master
tags:
- "v*"
paths-ignore:
- "doc*/**"
- "./*.ya?ml"
- "**/*.md"
- "**/*.rst"
pull_request:
paths-ignore:
- "doc*/**"
- "./*.ya?ml"
- "**/*.md"
- "**/*.rst"
workflow_dispatch:
jobs:
init:
permissions:
contents: read
runs-on: ubuntu-latest
outputs:
module_name: ${{ steps.set_module_name.outputs.module_name }}
steps:
- name: Set module name
id: set_module_name
run: |
module_name=$(echo "${{ github.event.repository.name }}" | tr '-' '_')
echo "module_name=$module_name" >> "$GITHUB_OUTPUT"
echo "Computed module name: $module_name"
sdist:
needs: init
permissions:
contents: read
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Build source distribution (sdist)
run: pipx run build --sdist
- name: Upload source distribution as artifact
uses: actions/upload-artifact@v4
with:
name: ${MODULE_NAME}-sdist
path: dist
env:
MODULE_NAME: ${{ needs.init.outputs.module_name }}
wheel:
needs: init
permissions:
contents: read
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Build wheel (bdist)
run: pipx run build --wheel
- name: Upload wheel as artifact
uses: actions/upload-artifact@v4
with:
name: ${MODULE_NAME}-wheel
path: dist
env:
MODULE_NAME: ${{ needs.init.outputs.module_name }}
install_wheel:
needs: [init, wheel]
permissions:
contents: read
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
path: dist
merge-multiple: true
- name: Show downloaded artifacts
run: ls -lcahFR --color=auto dist
- name: Install wheel
run: |
pip install torch --index-url https://download.pytorch.org/whl/cpu
pip install dist/*.whl
- name: Test import
run: python -c "import ${MODULE_NAME}; print(${MODULE_NAME}.__version__)"
env:
MODULE_NAME: ${{ needs.init.outputs.module_name }}
upload_test_pypi:
needs: [sdist, wheel]
runs-on: ubuntu-latest
environment: release
permissions:
contents: read
id-token: write
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
steps:
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
path: dist
merge-multiple: true
- name: Publish to Test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
upload_pypi:
needs: [sdist, wheel, upload_test_pypi]
runs-on: ubuntu-latest
environment: release
permissions:
contents: read
id-token: write
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
steps:
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
path: dist
merge-multiple: true
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1