diff --git a/.github/workflows/_container.yml b/.github/workflows/_container.yml index da5e4936..bec61a29 100644 --- a/.github/workflows/_container.yml +++ b/.github/workflows/_container.yml @@ -36,25 +36,9 @@ jobs: - name: Test cli works in cached runtime image run: docker run --rm tag_for_testing --version - - - name: Create tags for publishing image - id: meta - uses: docker/metadata-action@v5 + + - name: Upload container as artifact + uses: actions/upload-artifact@v4 with: - images: ghcr.io/${{ github.repository }} - tags: | - type=ref,event=tag - type=raw,value=latest - - - name: Push cached image to container registry - if: github.ref_type == 'tag' - uses: docker/build-push-action@v6 - env: - DOCKER_BUILD_RECORD_UPLOAD: false - # This does not build the image again, it will find the image in the - # Docker cache and publish it - with: - context: . - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} + name: container + path: container diff --git a/.github/workflows/_docs.yml b/.github/workflows/_docs.yml index a1cafcae..90485e64 100644 --- a/.github/workflows/_docs.yml +++ b/.github/workflows/_docs.yml @@ -33,22 +33,3 @@ jobs: with: name: docs path: build - - - name: Sanitize ref name for docs version - run: echo "DOCS_VERSION=${GITHUB_REF_NAME//[^A-Za-z0-9._-]/_}" >> $GITHUB_ENV - - - name: Move to versioned directory - run: mv build/html .github/pages/$DOCS_VERSION - - - name: Write switcher.json - run: python .github/pages/make_switcher.py --add $DOCS_VERSION ${{ github.repository }} .github/pages/switcher.json - - - name: Publish Docs to gh-pages - if: github.ref_type == 'tag' || github.ref_name == 'main' - # We pin to the SHA, not the tag, for security reasons. - # https://docs.github.com/en/actions/learn-github-actions/security-hardening-for-github-actions#using-third-party-actions - uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4.0.0 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: .github/pages - keep_files: true diff --git a/.github/workflows/_push_container.yml b/.github/workflows/_push_container.yml new file mode 100644 index 00000000..49900927 --- /dev/null +++ b/.github/workflows/_push_container.yml @@ -0,0 +1,35 @@ +on: + workflow_call: + +jobs: + push: + runs-on: ubuntu-latest + + steps: + - name: Download container artifact + uses: actions/download-artifact@v4 + with: + name: container + path: container + + - name: Create tags for publishing image + id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository }} + tags: | + type=ref,event=tag + type=raw,value=latest + + - name: Push cached image to container registry + if: github.ref_type == 'tag' + uses: docker/build-push-action@v6 + env: + DOCKER_BUILD_RECORD_UPLOAD: false + # This does not build the image again, it will find the image in the + # Docker cache and publish it + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/_push_docs.yml b/.github/workflows/_push_docs.yml new file mode 100644 index 00000000..790b28fa --- /dev/null +++ b/.github/workflows/_push_docs.yml @@ -0,0 +1,38 @@ +on: + workflow_call: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + # Need this to get version number from last tag + fetch-depth: 0 + + - name: Download built docs artifact + uses: actions/download-artifact@v4 + with: + name: docs + path: build + + - name: Sanitize ref name for docs version + run: echo "DOCS_VERSION=${GITHUB_REF_NAME//[^A-Za-z-1-9._-]/_}" >> $GITHUB_ENV + + - name: Move to versioned directory + run: mv build/html .github/pages/$DOCS_VERSION + + - name: Write switcher.json + run: python .github/pages/make_switcher.py --add $DOCS_VERSION ${{ github.repository }} .github/pages/switcher.json + + - name: Publish Docs to gh-pages + if: github.ref_type == 'tag' || github.ref_name == 'main' + # We pin to the SHA, not the tag, for security reasons. + # https://docs.github.com/en/actions/learn-github-actions/security-hardening-for-github-actions#using-third-party-actions + uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4.0.0 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: .github/pages + keep_files: true diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f198a244..966af2f7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,6 +32,12 @@ jobs: permissions: contents: write + push_docs: + needs: docs + uses: ./.github/workflows/_push_docs.yml + permissions: + contents: write + example: needs: test if: github.ref_name == 'main' diff --git "a/template/{% if git_platform==\"github.com\" %}.github{% endif %}/workflows/ci.yml.jinja" "b/template/{% if git_platform==\"github.com\" %}.github{% endif %}/workflows/ci.yml.jinja" index c6ed106f..7bdd0532 100644 --- "a/template/{% if git_platform==\"github.com\" %}.github{% endif %}/workflows/ci.yml.jinja" +++ "b/template/{% if git_platform==\"github.com\" %}.github{% endif %}/workflows/ci.yml.jinja" @@ -41,11 +41,25 @@ jobs: permissions: contents: read packages: write + + push_container: + if: github.ref_type == 'tag' + needs: [container, test] + uses: ./.github/workflows/_push_container.yml + permissions: + contents: read + packages: write {% endif %}{% if sphinx %} docs: needs: check if: needs.check.outputs.branch-pr == '' uses: ./.github/workflows/_docs.yml + + push_docs: + needs: docs + uses: ./.github/workflows/_push_docs.yml + permissions: + contents: write {% endif %} dist: needs: check @@ -54,14 +68,14 @@ jobs: {% if pypi %} pypi: if: github.ref_type == 'tag' - needs: dist + needs: [dist, test] uses: ./.github/workflows/_pypi.yml permissions: id-token: write {% endif %} release: if: github.ref_type == 'tag' - needs: [dist{% if sphinx %}, docs{% endif %}] + needs: [dist, test{% if sphinx %}, docs{% endif %}] uses: ./.github/workflows/_release.yml permissions: contents: write diff --git "a/template/{% if git_platform==\"github.com\" %}.github{% endif %}/workflows/{% if docker %}_push_container.yml{% endif %}" "b/template/{% if git_platform==\"github.com\" %}.github{% endif %}/workflows/{% if docker %}_push_container.yml{% endif %}" new file mode 120000 index 00000000..daeafe96 --- /dev/null +++ "b/template/{% if git_platform==\"github.com\" %}.github{% endif %}/workflows/{% if docker %}_push_container.yml{% endif %}" @@ -0,0 +1 @@ +../../../.github/workflows/_push_container.yml \ No newline at end of file diff --git "a/template/{% if git_platform==\"github.com\" %}.github{% endif %}/workflows/{% if sphinx %}_push_docs.yml{% endif %}" "b/template/{% if git_platform==\"github.com\" %}.github{% endif %}/workflows/{% if sphinx %}_push_docs.yml{% endif %}" new file mode 120000 index 00000000..0c8d3868 --- /dev/null +++ "b/template/{% if git_platform==\"github.com\" %}.github{% endif %}/workflows/{% if sphinx %}_push_docs.yml{% endif %}" @@ -0,0 +1 @@ +../../../.github/workflows/_push_docs.yml \ No newline at end of file