Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation about setting up towncrier on pipelines #443

Open
qequ opened this issue Oct 20, 2022 · 7 comments
Open

Documentation about setting up towncrier on pipelines #443

qequ opened this issue Oct 20, 2022 · 7 comments

Comments

@qequ
Copy link

qequ commented Oct 20, 2022

The main documentation of towncrier lacks information about setting up towncrier to work on github/gitlab pipelines. It would be great to add configuration steps for that

@adiroiban
Copy link
Member

Towncrier uses GitHub Actions ... so I think that can be used as an example.

I don't much experience with GitLab / Azure Pipelines / Circle CI.

But towncrier is quite simple.
Do we need separate dedicated documentation for GitLab for example ?

@qequ
Copy link
Author

qequ commented Nov 10, 2022

My main concern with towncrier in gitlab's pipeline is about the process of building the changelog in the pipeline.
The check command works fine using a job like this;

  created-fragment:
    stage: lint
    rules:
      - if: $CI_MERGE_REQUEST_ID
    before_script:
      - python -m pip install towncrier
    script:
      - git fetch --no-tags origin +refs/heads/$CI_DEFAULT_BRANCH:refs/remotes/origin/$CI_DEFAULT_BRANCH
      - python -m towncrier check --compare-with origin/$CI_DEFAULT_BRANCH

I think it's quite similar to github, fetching data from the default branch and comparing changes.

But when trying to create and pushing the changelog it breaks because can't push to the main branch. The job is like this

publish-news:
  stage: generate-changelog
  rules:
    - if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"
  before_script:
    - curl -sSL https://install.python-poetry.org | python3 -
    - python -m pip install towncrier
  script:
    - towncrier build  --version "$VERSION" --yes
    - git commit -m "Add changelog"
    - git push origin HEAD:$CI_DEFAULT_BRANCH

Don't know if it's a configuration issue or gitlab can't handle pushing elements from the pipeline.

How is the build command handled with github actions?

@adiroiban
Copy link
Member

This look like generic git usage in GitLab and not towncrier.

the git command is the tool that can't push.

This doesn't look like a towncrier issue.


What I do, is run towncrier build on my local system, review the generated version and then I manually commit and push the final release notes.

@qequ
Copy link
Author

qequ commented Nov 10, 2022

so the usual way to publish changelogs is manually?

@adiroiban
Copy link
Member

Thanks for the info. I got it :)

Is not that towncrier should only be use for manualy processes.

But from what you are describing, the issue is with configuring GitLab to push a change back to the repo. This is a git configuration and not a towncrier configuration.

The same issue you would have if you want to make an automatic change with towncrier, or with black and then try to push the changes back.


I am not saying that we should not have that type of information.
Is just that the solution for this is not Towncrier specific.

As you mentioned, the automated changelog/release-notes files using towncrier works... it fails when trying to use git to push the file back.

@dklimpel
Copy link

@qequ
a gitlab job that works for me to push the changelog file:

publish-news:
  image:
    name: python:3.11-alpine
  before_script:
  - apk add -U git
  - python -m pip install towncrier
  stage: package
  needs: []
  variables:
    COMMIT_MESSAGE: Update `CHANGELOG.md` for next version
    COMMIT_FILES: CHANGELOG.md changelog.d/
  script:
  - towncrier build --version "$CHART_VERSION" --yes
  - |-
    CHANGES=$(git status --porcelain | wc -l)
    if [ $CHANGES -gt 0 ];then
      echo "committing"
      git config --global user.name ${GITLAB_USER_NAME}
      git config --global user.email "${GITLAB_USER_EMAIL}"
      git add ${COMMIT_FILES}
      git commit -m "${COMMIT_MESSAGE}"
      git push -o ci.skip https://gitlab-ci-token:${TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH} HEAD:${CI_COMMIT_REF_NAME}
    else
      echo "no change, nothing to commit"
    fi

@qequ
Copy link
Author

qequ commented Feb 6, 2023

CC: @dgutson @Franco0700

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants