ci(test): skip test-trigger-other-job when token is read-only #48
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Test | |
| on: | |
| pull_request: | |
| branches: | |
| - main | |
| jobs: | |
| test-installs: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: ./ | |
| - name: Test it was installed | |
| run: | | |
| cz version | |
| test-version: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: ./ | |
| with: | |
| version: 4.0.0 | |
| - name: Test version matches | |
| uses: actions/github-script@v8 | |
| with: | |
| script: | | |
| const assert = require('node:assert/strict'); | |
| const czVersion = await exec.getExecOutput('cz', ['version']); | |
| const expectedVersion = '4.0.0'; | |
| assert.equal(czVersion.stdout.trim(), expectedVersion); | |
| test-extra-requirements: | |
| strategy: | |
| matrix: | |
| extra_requirements: | |
| - pip_name: cz-conventional-gitmoji | |
| cz_name: cz_gitmoji | |
| - pip_name: cz-kpn | |
| cz_name: cz_kpn | |
| - pip_name: cz-kpn cz-conventional-gitmoji==0.7.0 | |
| cz_name: cz_kpn | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: ./ | |
| with: | |
| extra-requirements: ${{ matrix.extra_requirements.pip_name }} | |
| - name: Test extra requirements were installed | |
| uses: actions/github-script@v8 | |
| env: | |
| EXTRA_REQUIREMENTS: ${{ matrix.extra_requirements.cz_name }} | |
| with: | |
| script: | | |
| const assert = require('node:assert/strict'); | |
| const extraRequirements = process.env.EXTRA_REQUIREMENTS; | |
| const czList = await exec.getExecOutput('cz', ['ls']); | |
| const allItems = czList.stdout.trim().split('\n'); | |
| const result = allItems.includes(extraRequirements); | |
| assert.ok(result, `Expected ${extraRequirements} to be included in the list of installed cz plugins, but it was not.`); | |
| test-get-changelog: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - uses: ./ | |
| - name: Build changelog | |
| env: | |
| GIVEN_VERSION: "v0.1.0" | |
| run: | | |
| cz changelog --dry-run "${GIVEN_VERSION}" > .changelog.md | |
| - name: Verify changelog content | |
| uses: actions/github-script@v8 | |
| with: | |
| script: | | |
| const assert = require('node:assert/strict'); | |
| const fs = require('node:fs'); | |
| const changelogContent = fs.readFileSync('.changelog.md', 'utf8'); | |
| assert.ok(changelogContent.includes('v0.1.0 (2025-11-20)'), 'Expected changelog to contain version 0.1.0'); | |
| assert.ok(changelogContent.includes('### Feat'), 'Expected changelog to contain a header for features'); | |
| assert.ok(changelogContent.includes('### Fix'), 'Expected changelog to contain a header for fixes'); | |
| test-trigger-other-job: | |
| runs-on: ubuntu-latest | |
| # Skip when the token will be read-only and `gh workflow run` would | |
| # fail with HTTP 403 ("Resource not accessible by integration"): | |
| # - Fork PRs: GITHUB_TOKEN is always read-only on fork-originated PRs. | |
| # - Dependabot PRs: even though the branch is in the same repo, the | |
| # dependabot[bot] actor receives a restricted token by default. | |
| if: >- | |
| github.event.pull_request.head.repo.full_name == github.repository && | |
| github.actor != 'dependabot[bot]' | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - uses: ./ | |
| - id: get-version | |
| run: | | |
| current_version="$(cz version -p)" # ATTENTION: You may have to add the v* at the beginning of the version | |
| echo "current_version=$current_version" >> $GITHUB_OUTPUT | |
| - name: trigger other workflow | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| gh workflow list | |
| gh workflow run .github/workflows/trigger-me.yaml \ | |
| --ref "${{ github.head_ref }}" \ | |
| -f "version=${{ steps.get-version.outputs.current_version }}" | |
| test-python-version: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - uses: ./ | |
| with: | |
| python-version: "3.13" | |
| - id: get-version | |
| run: | | |
| python --version | |
| cz version |