From 98cb3879712508bc1deee47415ad436f64be0fa8 Mon Sep 17 00:00:00 2001 From: Simon Powell Date: Mon, 9 Sep 2024 13:36:41 +0100 Subject: [PATCH 1/4] Add release workflow --- .github/workflows/main.yml | 2 +- .github/workflows/release.yml | 68 ++++++++++++++++++++++++++++++++++ .gitignore | 1 + .goreleaser.yaml | 49 ++++++++++++++++++++++++ CHANGELOG.md | 0 changes/README.md | 31 ++++++++++++++++ changes/version.properties | 6 +++ pyproject.toml | 70 +++++++++++++++++++++++++++++++++++ 8 files changed, 226 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/release.yml create mode 100644 .gitignore create mode 100644 .goreleaser.yaml create mode 100644 CHANGELOG.md create mode 100644 changes/README.md create mode 100644 changes/version.properties create mode 100644 pyproject.toml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4cac744..fb1571e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,7 +17,7 @@ jobs: with: go-version: "1.22.2" - - name: Install depedencies + - name: Install dependencies run: sudo apt-get install libbtrfs-dev -y - name: Download Go Modules diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..bedf9a0 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,68 @@ +name: GitHub Release + +on: + workflow_dispatch: + +env: + go-version: '1.22.2' + python-version: '3.10' + +jobs: + # News file based version calculation + create-release: + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + + - uses: tibdex/github-app-token@v2 + id: get_installation_token + with: + app_id: 366894 + private_key: ${{ secrets.OTG_PLATFORM_APP_PRIVATE_KEY }} + + # Checkout with full history so commit number can be calculated for beta versions + - uses: actions/checkout@v4 + with: + token: ${{ steps.get_installation_token.outputs.token }} + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: ${{ env.go-version }} + + # Towncrier and CI tools are written in Python + - uses: actions/setup-python@v5 + with: + python-version: ${{ env.python-version }} + + - name: Install CI tools + run: pip install continuous-delivery-scripts + + - name: Generate release notes from news files + run: cd-generate-news --release-type release + + - name: Determine version number based on news files + run: | + echo "SEMVER_VERSION=$(cd-determine-version --release-type release)" >> $GITHUB_ENV + - name: Report version number for run + run: | + echo "::notice:: Releasing $SEMVER_VERSION" + + - name: Commit changes + uses: EndBug/add-and-commit@v9.1.4 + with: + author_name: monty-bot + author_email: monty-bot@arm.com + message: "Release v${{ env.SEMVER_VERSION }} [skip ci]" + add: "changes" + tag: "v${{ env.SEMVER_VERSION }} -m 'Release v${{ env.SEMVER_VERSION }}'" + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v6 + with: + distribution: goreleaser + version: '~> v2' + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..849ddff --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..b612f2f --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,49 @@ +# Goreleaser config for Armer +# Make sure to check the documentation at https://goreleaser.com + +# The lines below are called `modelines`. See `:help modeline` +# Feel free to remove those if you don't want/need to use them. +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json +# vim: set ts=2 sw=2 tw=0 fo=cnqoj + +version: 2 + +before: + hooks: + - go mod tidy + +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin + goarch: + - amd64 + - arm64 + +archives: + - format: tar.gz + # this name template makes the OS and Arch compatible with the results of `uname`. + name_template: >- + {{ .ProjectName }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} + # use zip for windows archives + format_overrides: + - goos: windows + format: zip + +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" +release: + draft: true + replace_existing_draft: true diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..e69de29 diff --git a/changes/README.md b/changes/README.md new file mode 100644 index 0000000..a5af014 --- /dev/null +++ b/changes/README.md @@ -0,0 +1,31 @@ + +# Changes directory + +This directory comprises information about all the changes that happened since the last release. + +A news file should be added to this directory for each PR. + +On release of the action, the content of the file becomes part of the [change log](../CHANGELOG.md) and this directory is reset. + +## News Files + +News files serve a different purpose to commit messages, which are generally written to inform developers of the +project. News files will form part of the release notes so should be written to target the consumer of the GitHub action. + +- At least, one news file should be added for each Merge/Pull request to the directory `/changes`. +- The text of the file should be a single line describing the change and/or impact to the user. +- The filename of the news file should take the form `.`, e.g, `20191231.feature` where: + - The number is either the issue number or, if no issue exists, the date in the form `YYYYMMDDHHMM`. + - The extension should indicate the type of change as described in the following table: + +| Change Type | Extension | Version Impact | +|-------------------------------------------------------------------------------------------------------------------------|------------|-----------------| +| Backwards compatibility breakages or significant changes denoting a shift direction. | `.major` | Major increment | +| New features and enhancements (non breaking). | `.feature` | Minor increment | +| Bug fixes or corrections (non breaking). | `.bugfix` | Patch increment | +| Documentation impacting the consumer of the package (not repo documentation, such as this file, for this use `.misc`). | `.doc` | N/A | +| Deprecation of functionality or interfaces (not actual removal, for this use `.major`). | `.removal` | None | +| Changes to the repository that do not impact functionality e.g. build scripts change. | `.misc` | None | \ No newline at end of file diff --git a/changes/version.properties b/changes/version.properties new file mode 100644 index 0000000..53b2cba --- /dev/null +++ b/changes/version.properties @@ -0,0 +1,6 @@ +# Semantic version number is automatically maintained by creating news files and releasing via CI. +VERSION=0.0.0 +COMMIT=bdf3f63700313295382f1e9c896f1a3bf9e1cbaa +MAJOR=0 +MINOR=0 +PATCH=0 \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..1cc63bf --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,70 @@ +[ProjectConfig] +MASTER_BRANCH = "main" +PROJECT_NAME = "armer" +PROJECT_ROOT = "." +PROJECT_UUID = "576e054b-f0a7-4ae8-be5c-090de20ed0ca" +NEWS_DIR = "changes/" +RELEASE_BRANCH_PATTERN = "*" +VERSION_FILE_PATH = "changes/version.properties" +CHANGELOG_FILE_PATH = "CHANGELOG.md" +PROGRAMMING_LANGUAGE = "go" + +AWS_BUCKET="" +SOURCE_DIR = "" +MODULE_TO_DOCUMENT = "" +DOCUMENTATION_DEFAULT_OUTPUT_PATH = "./does-not-exist" +DOCUMENTATION_PRODUCTION_OUTPUT_PATH = "./does-not-exist" + +[tool.towncrier] +directory = "changes" +filename = "CHANGELOG.md" +title_format = false + +[[tool.towncrier.type]] +directory = "major" +name = "Major changes" +showcontent = true + +[[tool.towncrier.type]] +directory = "feature" +name = "Features" +showcontent = true + +[[tool.towncrier.type]] +directory = "bugfix" +name = "Bugfixes" +showcontent = true + +[[tool.towncrier.type]] +directory = "doc" +name = "Improved Documentation" +showcontent = true + +[[tool.towncrier.type]] +directory = "removal" +name = "Deprecations and Removals" +showcontent = true + +[[tool.towncrier.type]] +directory = "misc" +name = "Misc" +showcontent = false + +[AutoVersionConfig] +CONFIG_NAME = "DEFAULT" +PRERELEASE_TOKEN = "beta" +BUILD_TOKEN = "dev" +TAG_TEMPLATE = "v{version}" +targets = [ "changes/version.properties",] + +[AutoVersionConfig.key_aliases] +VERSION = "VERSION_KEY" +MAJOR = "major" +MINOR = "minor" +PATCH = "patch" +COMMIT = "COMMIT" + +[AutoVersionConfig.trigger_patterns] +major = "changes/*.major" +minor = "changes/*.feature" +patch = "changes/*.bugfix" From 16ed415036ae899ba9b554104347de82557b8055 Mon Sep 17 00:00:00 2001 From: Simon Powell Date: Fri, 13 Sep 2024 09:38:54 +0100 Subject: [PATCH 2/4] Add news file check --- .github/workflows/news.yaml | 53 +++++++++++++++++++++++++++++++++++ .github/workflows/release.yml | 4 +-- changes/5.misc | 1 + 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/news.yaml create mode 100644 changes/5.misc diff --git a/.github/workflows/news.yaml b/.github/workflows/news.yaml new file mode 100644 index 0000000..33030dc --- /dev/null +++ b/.github/workflows/news.yaml @@ -0,0 +1,53 @@ +name: Check news + +on: + pull_request: + branches: + - main + +env: + python-version: '3.10' + dependabot_user: "dependabot[bot]" + +permissions: + contents: read + +jobs: + # Check that a news file has been added to this branch when a PR is created + assert-news: + name: Assert news files + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + # Checkout with full history for to allow compare with base branch + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + # Towncrier is written in Python + - uses: actions/setup-python@v5 + with: + python-version: ${{ env.python-version }} + + - name: Check for dependabot user + if: github.event.pull_request.user.login == env.dependabot_user + run: | + echo "::warning:: Skipping news file check as this is a dependency update and not included in the release notes." + + - name: Install CI tools + if: github.event.pull_request.user.login != env.dependabot_user + run: pip install towncrier + + # Fetch the base branch for the pull request so that towncrier can compare the current branch with the base branch. + - name: Check for news fragments + if: github.event.pull_request.user.login != env.dependabot_user + run: | + git fetch --no-tags origin +refs/heads/${BASE_BRANCH}:refs/remotes/origin/${BASE_BRANCH} + python -m towncrier.check --compare-with origin/${BASE_BRANCH} + env: + BASE_BRANCH: ${{ github.base_ref }} + + - name: Report failure if needed + if: ${{ failure() }} + run: | + echo "::error:: A news fragment explaining the change must be present in a pull request." \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bedf9a0..d0c97ad 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -52,8 +52,8 @@ jobs: - name: Commit changes uses: EndBug/add-and-commit@v9.1.4 with: - author_name: monty-bot - author_email: monty-bot@arm.com + author_name: otg-platform[bot] + author_email: 140601826+otg-platform[bot]@users.noreply.github.com message: "Release v${{ env.SEMVER_VERSION }} [skip ci]" add: "changes" tag: "v${{ env.SEMVER_VERSION }} -m 'Release v${{ env.SEMVER_VERSION }}'" diff --git a/changes/5.misc b/changes/5.misc new file mode 100644 index 0000000..5e1f1df --- /dev/null +++ b/changes/5.misc @@ -0,0 +1 @@ +Add release workflow From cbebefb17fa04ffef31c9a176b3adbfa2dcade6d Mon Sep 17 00:00:00 2001 From: Simon Powell Date: Fri, 13 Sep 2024 09:56:20 +0100 Subject: [PATCH 3/4] Fix Towncrier --- .goreleaser.yaml | 2 +- pyproject.toml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index b612f2f..50d18b5 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -45,5 +45,5 @@ changelog: - "^docs:" - "^test:" release: - draft: true + draft: false replace_existing_draft: true diff --git a/pyproject.toml b/pyproject.toml index 1cc63bf..6e89204 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,6 +19,7 @@ DOCUMENTATION_PRODUCTION_OUTPUT_PATH = "./does-not-exist" directory = "changes" filename = "CHANGELOG.md" title_format = false +ignore = version.properties [[tool.towncrier.type]] directory = "major" From 27fa7c26d59c004768e0a36348909bc502ae1bac Mon Sep 17 00:00:00 2001 From: Simon Powell Date: Fri, 13 Sep 2024 09:58:49 +0100 Subject: [PATCH 4/4] Correct toml format --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 6e89204..d3a122a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,7 +19,7 @@ DOCUMENTATION_PRODUCTION_OUTPUT_PATH = "./does-not-exist" directory = "changes" filename = "CHANGELOG.md" title_format = false -ignore = version.properties +ignore = [ "version.properties" ] [[tool.towncrier.type]] directory = "major"