|
| 1 | +--- |
| 2 | +name: 'publish-release' |
| 3 | +on: # yamllint disable-line rule:truthy |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v[0-9]+.[0-9]+.[0-9]+*' |
| 7 | +jobs: |
| 8 | + lint: |
| 9 | + name: 'lint' |
| 10 | + runs-on: 'ubuntu-22.04' |
| 11 | + steps: |
| 12 | + - uses: 'actions/checkout@v4' |
| 13 | + - uses: 'actions/setup-python@v5' |
| 14 | + with: |
| 15 | + python-version: '3.12' |
| 16 | + - name: 'Install hatch' |
| 17 | + run: 'pipx install hatch~=1.12.0' |
| 18 | + - name: 'Lint' |
| 19 | + run: 'hatch fmt --check' |
| 20 | + test: |
| 21 | + needs: |
| 22 | + - 'lint' |
| 23 | + name: "test" |
| 24 | + runs-on: 'ubuntu-22.04' |
| 25 | + steps: |
| 26 | + - uses: 'actions/checkout@v4' |
| 27 | + - name: 'Set up Python ${{ matrix.python-version }}' |
| 28 | + uses: 'actions/setup-python@v5' |
| 29 | + with: |
| 30 | + python-version: '3.12' |
| 31 | + - name: 'Install hatch' |
| 32 | + run: 'pipx install hatch~=1.12.0' |
| 33 | + - name: 'Test' |
| 34 | + run: 'hatch test --all --cover' |
| 35 | + - name: 'Collect coverage' |
| 36 | + uses: 'romeovs/lcov-reporter-action@v0.4.0' |
| 37 | + with: |
| 38 | + lcov-file: 'lcov.info' |
| 39 | + build: |
| 40 | + needs: |
| 41 | + - 'test' |
| 42 | + name: "build" |
| 43 | + runs-on: 'ubuntu-22.04' |
| 44 | + steps: |
| 45 | + - uses: 'actions/checkout@v4' |
| 46 | + - uses: 'actions/setup-python@v5' |
| 47 | + with: |
| 48 | + python-version: '3.12' |
| 49 | + - name: 'Install hatch' |
| 50 | + run: 'pipx install hatch~=1.12.0' |
| 51 | + - name: 'Get tag date' |
| 52 | + id: 'get_tag_date' |
| 53 | + run: 'echo "::set-output name=date::$(git log -1 --format=%aI ${{ github.ref }})"' |
| 54 | + - name: 'get version via hatch and validate with tag' |
| 55 | + run: |- |
| 56 | + VERSION_VIA_HATCH="$(hatch version)" |
| 57 | + VERSION_VIA_GITHUB="${{ github.ref }}" |
| 58 | + if [ "v${VERSION_VIA_HATCH}" != "${VERSION_VIA_GITHUB}" ] |
| 59 | + then |
| 60 | + echo "Projects version (hatch version -> ${VERSION_VIA_HATCH} does not match the version of git tagging"\ |
| 61 | + "(${VERSION_VIA_GITHUB}). Please fix the version in the code and try again.)" >&2 |
| 62 | + fi |
| 63 | + echo "VERSION=${VERSION_VIA_HATCH}" >> ${GITHUB_ENV} |
| 64 | + - name: 'Build' |
| 65 | + run: 'hatch build' |
| 66 | + - uses: 'actions/upload-artifact@v4' |
| 67 | + with: |
| 68 | + name: 'dist' |
| 69 | + path: './dist/' |
| 70 | + if-no-files-found: 'error' |
| 71 | + - name: 'Build Doc' |
| 72 | + run: 'hatch run mkdocs:build-archive' |
| 73 | + - uses: 'actions/upload-artifact@v4' |
| 74 | + with: |
| 75 | + name: 'documentation' |
| 76 | + path: 'jinja-file-renderer-doc-*.tar.xz' |
| 77 | + compression-level: 0 # no compression |
| 78 | + if-no-files-found: 'error' |
| 79 | + pypi-publish: |
| 80 | + needs: |
| 81 | + - 'build' |
| 82 | + name: 'Upload release to test-PyPI' |
| 83 | + runs-on: 'ubuntu-latest' |
| 84 | + environment: |
| 85 | + name: 'release' |
| 86 | + url: 'https://pypi.org/p/jinja-file-renderer' |
| 87 | + permissions: |
| 88 | + id-token: 'write' # IMPORTANT: this permission is mandatory for trusted publishing |
| 89 | + steps: |
| 90 | + - name: 'Get artifact "dist"' |
| 91 | + uses: 'actions/download-artifact@v4' |
| 92 | + with: |
| 93 | + name: 'dist' |
| 94 | + - run: 'ls -lah .' |
| 95 | + - name: 'Publish package distributions to Test-PyPI' |
| 96 | + uses: 'pypa/gh-action-pypi-publish@release/v1' |
| 97 | + with: |
| 98 | + print-hash: true |
| 99 | + github-release: |
| 100 | + needs: |
| 101 | + - 'pypi-publish' |
| 102 | + name: 'Create GitHub Release' |
| 103 | + runs-on: 'ubuntu-latest' |
| 104 | + steps: |
| 105 | + - name: 'Create GitHub Release Draft' |
| 106 | + uses: 'actions/create-release@v1' |
| 107 | + env: |
| 108 | + GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' # This token is provided automatically by Actions. |
| 109 | + with: |
| 110 | + tag_name: 'v${VERSION}' |
| 111 | + release_name: 'Release ${VERSION} (${{ steps.get_tag_date.outputs.date }})' |
| 112 | + body: |- |
| 113 | + Documentation: https://jinja-file-renderer.readthedocs.io/v${VERSION} |
| 114 | + Artifacts: https://pypi.org/project/jinja-file-renderer/${VERSION}/ |
| 115 | + draft: false |
| 116 | + prerelease: false |
0 commit comments