From e1b77b969569d9dca108cfad6a6cef4bcc8f6eeb Mon Sep 17 00:00:00 2001 From: "Xuan (Sean) Hu" Date: Mon, 29 Jan 2024 16:26:39 +0800 Subject: [PATCH] ci: Unify workflow names and orders. (#293) --- .github/workflows/devcontainer.yml | 2 +- .github/workflows/release.yml | 50 +++++++++---------- .gitlab-ci.yml | 2 +- .gitlab/{ci => workflows}/ci.yml | 0 .gitlab/{ci => workflows}/devcontainer.yml | 2 +- .gitlab/{ci => workflows}/mr.yml | 2 +- .../ci => .gitlab/workflows}/release.yml | 33 ++++++------ .vscode/settings.json | 5 ++ template/.vscode/settings.json | 5 ++ .../workflows/devcontainer.yml.jinja | 2 +- .../workflows/release.yml.jinja | 50 +++++++++---------- ...managed' %].gitlab-ci.yml[% endif %].jinja | 2 +- .../{ci => workflows}/ci.yml.jinja | 0 .../{ci => workflows}/devcontainer.yml | 2 +- .../{ci => workflows}/mr.yml | 2 +- .../workflows}/release.yml | 33 ++++++------ 16 files changed, 100 insertions(+), 92 deletions(-) rename .gitlab/{ci => workflows}/ci.yml (100%) rename .gitlab/{ci => workflows}/devcontainer.yml (97%) rename .gitlab/{ci => workflows}/mr.yml (97%) rename {template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/ci => .gitlab/workflows}/release.yml (90%) rename template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/{ci => workflows}/ci.yml.jinja (100%) rename template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/{ci => workflows}/devcontainer.yml (97%) rename template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/{ci => workflows}/mr.yml (97%) rename {.gitlab/ci => template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/workflows}/release.yml (90%) diff --git a/.github/workflows/devcontainer.yml b/.github/workflows/devcontainer.yml index cf8a73a9..e9c6ac31 100644 --- a/.github/workflows/devcontainer.yml +++ b/.github/workflows/devcontainer.yml @@ -3,7 +3,7 @@ concurrency: cancel-in-progress: true group: ${{ github.workflow }}-${{ github.ref }} jobs: - devcontainer_prebuild: + dev-container-publish: permissions: contents: read packages: write diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c07a9ae7..83f8dcb9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,19 +1,5 @@ name: Release jobs: - package: - needs: release - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: pdm-project/setup-pdm@v4 - with: - cache: true - python-version: '3.12' - - run: env | sort - - env: - PDM_PUBLISH_PASSWORD: ${{ secrets.PDM_PUBLISH_PASSWORD }} - PDM_PUBLISH_USERNAME: ${{ vars.PDM_PUBLISH_USERNAME != '' && vars.PDM_PUBLISH_USERNAME || '__token__' }} - run: make publish pages-build: runs-on: ubuntu-latest steps: @@ -36,17 +22,7 @@ jobs: uses: actions/upload-pages-artifact@v3 with: path: public - pages-deploy: - needs: release - permissions: - id-token: write - pages: write - runs-on: ubuntu-latest - steps: - - id: deployment - name: Deploy to GitHub Pages - uses: actions/deploy-pages@v4 - release: + release-publish: needs: pages-build permissions: contents: write @@ -77,6 +53,30 @@ jobs: with: body_path: release-notes.md prerelease: ${{ steps.prerelease.outputs.is_prerelease }} + package-publish: + needs: release-publish + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: pdm-project/setup-pdm@v4 + with: + cache: true + python-version: '3.12' + - run: env | sort + - env: + PDM_PUBLISH_PASSWORD: ${{ secrets.PDM_PUBLISH_PASSWORD }} + PDM_PUBLISH_USERNAME: ${{ vars.PDM_PUBLISH_USERNAME != '' && vars.PDM_PUBLISH_USERNAME || '__token__' }} + run: make publish + pages: + needs: release-publish + permissions: + id-token: write + pages: write + runs-on: ubuntu-latest + steps: + - id: deployment + name: Deploy to GitHub Pages + uses: actions/deploy-pages@v4 on: push: tags: diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index dd7c640a..a4a4b0e9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,4 +6,4 @@ default: before_script: - env | sort image: ${CI_REGISTRY_IMAGE}:dev-py3.12 -include: .gitlab/ci/**.yml +include: .gitlab/workflows/**.yml diff --git a/.gitlab/ci/ci.yml b/.gitlab/workflows/ci.yml similarity index 100% rename from .gitlab/ci/ci.yml rename to .gitlab/workflows/ci.yml diff --git a/.gitlab/ci/devcontainer.yml b/.gitlab/workflows/devcontainer.yml similarity index 97% rename from .gitlab/ci/devcontainer.yml rename to .gitlab/workflows/devcontainer.yml index 98a47ca0..53777357 100644 --- a/.gitlab/ci/devcontainer.yml +++ b/.gitlab/workflows/devcontainer.yml @@ -1,4 +1,4 @@ -devcontainer-prebuild: +dev-container-publish: image: docker:latest interruptible: true parallel: diff --git a/.gitlab/ci/mr.yml b/.gitlab/workflows/mr.yml similarity index 97% rename from .gitlab/ci/mr.yml rename to .gitlab/workflows/mr.yml index 2240fec6..ca8e8e5f 100644 --- a/.gitlab/ci/mr.yml +++ b/.gitlab/workflows/mr.yml @@ -1,4 +1,4 @@ -lint_title: +lint-title: interruptible: true rules: - if: $CI_PIPELINE_SOURCE == 'merge_request_event' diff --git a/template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/ci/release.yml b/.gitlab/workflows/release.yml similarity index 90% rename from template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/ci/release.yml rename to .gitlab/workflows/release.yml index beacf89d..1be468bb 100644 --- a/template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/ci/release.yml +++ b/.gitlab/workflows/release.yml @@ -1,4 +1,4 @@ -doc: +pages-build: artifacts: paths: - public @@ -11,9 +11,21 @@ doc: - make doc - make release-notes > release-notes.md stage: release -package: +release-publish: + image: registry.gitlab.com/gitlab-org/release-cli:latest + needs: + - pages-build + release: + description: release-notes.md + tag_name: $CI_COMMIT_TAG + rules: + - if: $CI_COMMIT_TAG =~ /^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-?(a|b|rc)(0|[1-9][0-9]*)?)?$/ + script: + - echo "Running the release job." + stage: release +package-publish: needs: - - release + - release-publish rules: - if: $CI_COMMIT_TAG =~ /^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-?(a|b|rc)(0|[1-9][0-9]*)?)?$/ script: @@ -24,22 +36,9 @@ pages: paths: - public needs: - - release - - doc + - release-publish rules: - if: $CI_COMMIT_TAG =~ /^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-?(a|b|rc)(0|[1-9][0-9]*)?)?$/ script: - echo "Running the pages job." stage: release -release: - image: registry.gitlab.com/gitlab-org/release-cli:latest - needs: - - doc - release: - description: release-notes.md - tag_name: $CI_COMMIT_TAG - rules: - - if: $CI_COMMIT_TAG =~ /^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-?(a|b|rc)(0|[1-9][0-9]*)?)?$/ - script: - - echo "Running the release job." - stage: release diff --git a/.vscode/settings.json b/.vscode/settings.json index 73f2671b..a0bfeb89 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -138,6 +138,11 @@ "min_py", "max_py", "default_py", + "id-token", + "pages-build", + "release-publish", + "package-publish", + "pages", "3.8", "3.9", "3.10", diff --git a/template/.vscode/settings.json b/template/.vscode/settings.json index 73f2671b..a0bfeb89 100644 --- a/template/.vscode/settings.json +++ b/template/.vscode/settings.json @@ -138,6 +138,11 @@ "min_py", "max_py", "default_py", + "id-token", + "pages-build", + "release-publish", + "package-publish", + "pages", "3.8", "3.9", "3.10", diff --git a/template/[% if repo_host_type == 'github.com' %].github[% endif %]/workflows/devcontainer.yml.jinja b/template/[% if repo_host_type == 'github.com' %].github[% endif %]/workflows/devcontainer.yml.jinja index 3484e117..1bbf2d51 100644 --- a/template/[% if repo_host_type == 'github.com' %].github[% endif %]/workflows/devcontainer.yml.jinja +++ b/template/[% if repo_host_type == 'github.com' %].github[% endif %]/workflows/devcontainer.yml.jinja @@ -4,7 +4,7 @@ concurrency: cancel-in-progress: true group: {{ '${{ github.workflow }}-${{ github.ref }}' }} jobs: - devcontainer_prebuild: + dev-container-publish: permissions: contents: read packages: write diff --git a/template/[% if repo_host_type == 'github.com' %].github[% endif %]/workflows/release.yml.jinja b/template/[% if repo_host_type == 'github.com' %].github[% endif %]/workflows/release.yml.jinja index 80a8ee9b..bae1fcc1 100644 --- a/template/[% if repo_host_type == 'github.com' %].github[% endif %]/workflows/release.yml.jinja +++ b/template/[% if repo_host_type == 'github.com' %].github[% endif %]/workflows/release.yml.jinja @@ -1,19 +1,5 @@ name: Release jobs: - package: - needs: release - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: pdm-project/setup-pdm@v4 - with: - cache: true - python-version: '{{ default_py }}' - - run: env | sort - - env: - PDM_PUBLISH_PASSWORD: {{ '${{ secrets.PDM_PUBLISH_PASSWORD }}' }} - PDM_PUBLISH_USERNAME: {{ '${{ vars.PDM_PUBLISH_USERNAME != \'\' && vars.PDM_PUBLISH_USERNAME || \'__token__\' }}' }} - run: make publish pages-build: runs-on: ubuntu-latest steps: @@ -36,17 +22,7 @@ jobs: uses: actions/upload-pages-artifact@v3 with: path: public - pages-deploy: - needs: release - permissions: - id-token: write - pages: write - runs-on: ubuntu-latest - steps: - - id: deployment - name: Deploy to GitHub Pages - uses: actions/deploy-pages@v4 - release: + release-publish: needs: pages-build permissions: contents: write @@ -77,6 +53,30 @@ jobs: with: body_path: release-notes.md prerelease: {{ '${{ steps.prerelease.outputs.is_prerelease }}' }} + package-publish: + needs: release-publish + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: pdm-project/setup-pdm@v4 + with: + cache: true + python-version: '{{ default_py }}' + - run: env | sort + - env: + PDM_PUBLISH_PASSWORD: {{ '${{ secrets.PDM_PUBLISH_PASSWORD }}' }} + PDM_PUBLISH_USERNAME: {{ '${{ vars.PDM_PUBLISH_USERNAME != \'\' && vars.PDM_PUBLISH_USERNAME || \'__token__\' }}' }} + run: make publish + pages: + needs: release-publish + permissions: + id-token: write + pages: write + runs-on: ubuntu-latest + steps: + - id: deployment + name: Deploy to GitHub Pages + uses: actions/deploy-pages@v4 on: push: tags: diff --git a/template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab-ci.yml[% endif %].jinja b/template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab-ci.yml[% endif %].jinja index 3129949b..49452351 100644 --- a/template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab-ci.yml[% endif %].jinja +++ b/template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab-ci.yml[% endif %].jinja @@ -6,4 +6,4 @@ default: before_script: - env | sort image: ${CI_REGISTRY_IMAGE}:dev-py{{ default_py }} -include: .gitlab/ci/**.yml +include: .gitlab/workflows/**.yml diff --git a/template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/ci/ci.yml.jinja b/template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/ci.yml.jinja similarity index 100% rename from template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/ci/ci.yml.jinja rename to template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/ci.yml.jinja diff --git a/template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/ci/devcontainer.yml b/template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/devcontainer.yml similarity index 97% rename from template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/ci/devcontainer.yml rename to template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/devcontainer.yml index 98a47ca0..53777357 100644 --- a/template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/ci/devcontainer.yml +++ b/template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/devcontainer.yml @@ -1,4 +1,4 @@ -devcontainer-prebuild: +dev-container-publish: image: docker:latest interruptible: true parallel: diff --git a/template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/ci/mr.yml b/template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/mr.yml similarity index 97% rename from template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/ci/mr.yml rename to template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/mr.yml index 2240fec6..ca8e8e5f 100644 --- a/template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/ci/mr.yml +++ b/template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/mr.yml @@ -1,4 +1,4 @@ -lint_title: +lint-title: interruptible: true rules: - if: $CI_PIPELINE_SOURCE == 'merge_request_event' diff --git a/.gitlab/ci/release.yml b/template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/release.yml similarity index 90% rename from .gitlab/ci/release.yml rename to template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/release.yml index beacf89d..1be468bb 100644 --- a/.gitlab/ci/release.yml +++ b/template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/release.yml @@ -1,4 +1,4 @@ -doc: +pages-build: artifacts: paths: - public @@ -11,9 +11,21 @@ doc: - make doc - make release-notes > release-notes.md stage: release -package: +release-publish: + image: registry.gitlab.com/gitlab-org/release-cli:latest + needs: + - pages-build + release: + description: release-notes.md + tag_name: $CI_COMMIT_TAG + rules: + - if: $CI_COMMIT_TAG =~ /^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-?(a|b|rc)(0|[1-9][0-9]*)?)?$/ + script: + - echo "Running the release job." + stage: release +package-publish: needs: - - release + - release-publish rules: - if: $CI_COMMIT_TAG =~ /^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-?(a|b|rc)(0|[1-9][0-9]*)?)?$/ script: @@ -24,22 +36,9 @@ pages: paths: - public needs: - - release - - doc + - release-publish rules: - if: $CI_COMMIT_TAG =~ /^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-?(a|b|rc)(0|[1-9][0-9]*)?)?$/ script: - echo "Running the pages job." stage: release -release: - image: registry.gitlab.com/gitlab-org/release-cli:latest - needs: - - doc - release: - description: release-notes.md - tag_name: $CI_COMMIT_TAG - rules: - - if: $CI_COMMIT_TAG =~ /^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-?(a|b|rc)(0|[1-9][0-9]*)?)?$/ - script: - - echo "Running the release job." - stage: release