diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4610fa923..515baecf5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,19 +1,50 @@ +# on: +# workflow_dispatch: +# inputs: +# version: +# type: string +# description: 'Version' +# required: true on: push: branches: - - master + - feat/changelog permissions: contents: write pull-requests: write -name: release-please +name: release jobs: - release-please: + tag: runs-on: ubuntu-latest steps: - - uses: googleapis/release-please-action@v4 + - uses: actions/checkout@v4 with: - token: ${{ secrets.GH_TOKEN }} - release-type: simple + fetch-depth: 0 + - name: Install Neovim + uses: rhysd/action-setup-vim@v1 + id: neovim + with: + neovim: true + version: v0.10.3 + - name: Update changelog + run: | + nvim -l scripts/generate_changelog.lua 0.4.2 + # nvim -l scripts/generate_changelog.lua ${{ github.event.inputs.version }} + - name: Print generated changelog + run: | + cat docs/changelog.org + - name: Get release info + id: release_info + run: | + changes=$(nvim -l scripts/generate_changelog.lua 0.4.2 print) + { + echo 'output<> $GITHUB_OUTPUT + - name: Print release info + run: + echo "${{ steps.release_info.outputs.output }}" diff --git a/scripts/generate_changelog.lua b/scripts/generate_changelog.lua index e8e137b1e..6378a2563 100644 --- a/scripts/generate_changelog.lua +++ b/scripts/generate_changelog.lua @@ -11,9 +11,12 @@ local function populate_section(content, name, list) ) content[#content + 1] = '' end -local function generate_changelog() - local latest_tag = vim.fn.system('git describe --tags `git rev-list --tags --max-count=1`'):gsub('\n', '') - local commits = vim.fn.systemlist('git log ' .. latest_tag .. "..master --pretty=format:'%s'") + +local function get_changes(latest_tag) + if not latest_tag then + latest_tag = vim.fn.system('git describe --tags `git rev-list --tags --max-count=1`'):gsub('\n', '') + end + local commits = vim.fn.systemlist('git log ' .. latest_tag .. "..feat/changelog --pretty=format:'%s'") local fixes = {} local features = {} local breaking_changes = {} @@ -32,21 +35,31 @@ local function generate_changelog() end end end + local content = {} + + populate_section(content, 'Breaking changes', breaking_changes) + populate_section(content, 'Features', features) + populate_section(content, 'Bug fixes', fixes) + + return content +end + +local function generate_changelog() + local latest_tag = vim.fn.system('git describe --tags `git rev-list --tags --max-count=1`'):gsub('\n', '') local new_tag = arg[1] - local changelog = vim.fn.readfile('./docs/changelog.org') - local start = { unpack(changelog, 1, 2) } - local remaining = { unpack(changelog, 3) } local new_content = { '** ' .. new_tag, '- Date: [[' .. os.date('%Y-%m-%d') .. ']]', ('- [[https://github.com/nvim-orgmode/orgmode/compare/%s...%s][Compare]]'):format(latest_tag, new_tag), - ('- [[https://github.com/nvim-orgmode/orgmode/releases/tag/%s][Link to release]]'):format(latest_tag), + ('- [[https://github.com/nvim-orgmode/orgmode/releases/tag/%s][Link to release]]'):format(new_tag), '', } - populate_section(new_content, 'Breaking changes', breaking_changes) - populate_section(new_content, 'Features', features) - populate_section(new_content, 'Bug fixes', fixes) + vim.list_extend(new_content, get_changes(latest_tag)) + + local changelog = vim.fn.readfile('./docs/changelog.org') + local start = { unpack(changelog, 1, 2) } + local remaining = { unpack(changelog, 3) } local new_changelog = vim.list_extend(start, new_content) new_changelog = vim.list_extend(new_changelog, remaining) @@ -54,4 +67,8 @@ local function generate_changelog() vim.fn.writefile(new_changelog, './docs/changelog.org') end +if arg[2] and arg[2] == 'print' then + return io.write(table.concat(get_changes(), '\n')) +end + generate_changelog()