Trigger Github actions from tags
DELETE
.github/workflows/draft-release-notes-on-milestone-close.yaml
-name: Create draft release notes
-on:
- milestone:
- types: [closed]
-
-jobs:
- draft_release_notes:
- runs-on: ubuntu-latest
- steps:
- - name: Get pull requests for milestone
- id: pullsA
- uses: actions/github-script@0.9.0
- with:
- github-token: ${{secrets.GITHUB_TOKEN}}
- script: |
- const options = github.pulls.list.endpoint.merge({
- owner: context.repo.owner,
- repo: context.repo.repo,
- state: 'closed'
- })
-
- const pullRequests = await github.paginate(options)
-
- return pullRequests.filter(pullRequest => pullRequest.merged_at
- && pullRequest.milestone
- && pullRequest.milestone.number == ${{ github.event.milestone.number }})
- - name: Generate release notes text
- id: generate
- uses: actions/github-script@0.9.0
- with:
- github-token: ${{secrets.GITHUB_TOKEN}}
- script: |
- var draftText = "# Improvements \n\n# Changes \n\n"
- for (let pull of ${{ steps.pullsA.outputs.result }}) {
- draftText += "* " + pull.title + " #" + pull.number + " \n"
- }
- draftText += "\n# Fixes \n"
- return draftText
- - name: Create release notes draft
- uses: actions/github-script@0.9.0
- with:
- github-token: ${{secrets.GITHUB_TOKEN}}
- script: |
- await github.repos.createRelease({
- owner: context.repo.owner,
- repo: context.repo.repo,
- tag_name: 'v' + '${{ github.event.milestone.title }}',
- name: '${{ github.event.milestone.title}}',
- draft: true,
- body: ${{ steps.generate.outputs.result }}
- })
\ No newline at end of file

ADD
.github/workflows/draft-release-notes-on-tag.yaml
+name: Draft release notes on tag
+on:
+ create
+
+jobs:
+ draft_release_notes:
+ if: github.event.ref_type == 'tag' && github.event.master_branch == 'master'
+ runs-on: ubuntu-latest
+ steps:
+ - name: Get milestone title
+ id: milestoneTitle
+ uses: actions/github-script@0.9.0
+ with:
+ result-encoding: string
+ script: |
+ // Our tags are of the form vX.X.X and milestones don't have the "v"
+ return '${{github.event.ref}}'.startsWith('v') ? '${{github.event.ref}}'.substring(1) : '${{github.event.ref}}';
+ - name: Get milestone for tag
+ id: milestone
+ uses: actions/github-script@0.9.0
+ with:
+ github-token: ${{secrets.GITHUB_TOKEN}}
+ script: |
+ const options = github.issues.listMilestonesForRepo.endpoint.merge({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ state: 'all'
+ })
+
+ const milestones = await github.paginate(options)
+
+ const milestone = milestones.find( milestone => milestone.title == '${{steps.milestoneTitle.outputs.result}}' )
+
+ if (milestone) {
+ return milestone.number
+ } else {
+ return null
+ }
+ - name: Get pull requests for milestone
+ if: fromJSON(steps.milestone.outputs.result)
+ id: pulls
+ uses: actions/github-script@0.9.0
+ with:
+ github-token: ${{secrets.GITHUB_TOKEN}}
+ script: |
+ const options = github.pulls.list.endpoint.merge({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ state: 'closed'
+ })
+
+ const pullRequests = await github.paginate(options)
+
+ return pullRequests.filter(pullRequest => pullRequest.merged_at
+ && pullRequest.milestone
+ && pullRequest.milestone.number == ${{steps.milestone.outputs.result}})
+ - name: Generate release notes text
+ if: fromJSON(steps.milestone.outputs.result)
+ id: generate
+ uses: actions/github-script@0.9.0
+ with:
+ github-token: ${{secrets.GITHUB_TOKEN}}
+ result-encoding: string
+ script: |
+ var draftText = "# Improvements \n\n# Changes \n\n"
+ for (let pull of ${{ steps.pulls.outputs.result }}) {
+ draftText += "* " + pull.title + " #" + pull.number + " \n"
+ }
+ draftText += "\n# Fixes \n"
+ return draftText
+ - name: Create release notes
+ if: fromJSON(steps.milestone.outputs.result)
+ # can't use actions/create-release because it doesn't like the text coming from JS
+ uses: actions/github-script@0.9.0
+ with:
+ github-token: ${{secrets.GITHUB_TOKEN}}
+ script: |
+ await github.repos.createRelease({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ tag_name: '${{ github.event.ref }}',
+ name: '${{ steps.milestoneTitle.outputs.result }}',
+ draft: true,
+ body: `${{ steps.generate.outputs.result }}`
+ })
\ No newline at end of file

ADD
.github/workflows/increment-milestones-on-tag.yaml
+name: Increment milestones on tag
+on:
+ create
+
+jobs:
+ increment_milestone:
+ if: github.event.ref_type == 'tag' && github.event.master_branch == 'master'
+ runs-on: ubuntu-latest
+ steps:
+ - name: Get milestone title
+ id: milestoneTitle
+ uses: actions/github-script@0.9.0
+ with:
+ result-encoding: string
+ script: |
+ // Our tags are of the form vX.X.X and milestones don't have the "v"
+ return '${{github.event.ref}}'.startsWith('v') ? '${{github.event.ref}}'.substring(1) : '${{github.event.ref}}';
+ - name: Get milestone for tag
+ id: milestone
+ uses: actions/github-script@0.9.0
+ with:
+ github-token: ${{secrets.GITHUB_TOKEN}}
+ script: |
+ const options = github.issues.listMilestonesForRepo.endpoint.merge({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ state: 'all'
+ })
+
+ const milestones = await github.paginate(options)
+
+ const milestone = milestones.find( milestone => milestone.title == '${{steps.milestoneTitle.outputs.result}}' )
+
+ if (milestone) {
+ return milestone.number
+ } else {
+ return null
+ }
+ - name: Close milestone
+ if: fromJSON(steps.milestone.outputs.result)
+ uses: actions/github-script@0.9.0
+ with:
+ github-token: ${{secrets.GITHUB_TOKEN}}
+ script: |
+ await github.issues.updateMilestone({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ state: 'closed',
+ milestone_number: ${{steps.milestone.outputs.result}}
+ })
+ - name: Get next minor version
+ if: fromJSON(steps.milestone.outputs.result)
+ id: semvers
+ uses: WyriHaximus/github-action-next-semvers@0.1.0
+ with:
+ version: ${{steps.milestoneTitle.outputs.result}}
+ - name: Create next milestone
+ if: fromJSON(steps.milestone.outputs.result)
+ uses: WyriHaximus/github-action-create-milestone@0.1.0
+ with:
+ title: ${{ steps.semvers.outputs.minor }}
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
\ No newline at end of file

Trigger Github actions from tags