Debian Codegraph @

.github/workflows/changelog-and-release.yml

raw
1 name: Changelog and Release
2 # Update the changelog and news(optionally), bump the version, and create a release
3 #
4 # The release is created on the given branch, release and tag name format will be <version>-<branch> and
5 # the body of the release will be created from the changelog.txt or news element in the addon.xml.in
6 #
7 # options:
8 # - version_type: 'minor' / 'micro' # whether to do a minor or micro version bump
9 # - changelog_text: string to add to the changelog and news
10 # - update_news: 'true' / 'false' # whether to update the news in the addon.xml.in
11 # - add_date: 'true' / 'false' # Add date to version number in changelog and news. ie. v1.0.1 (2021-7-17)
12
13 on:
14 workflow_dispatch:
15 inputs:
16 version_type:
17 description: 'Create a ''minor'' or ''micro'' release?'
18 required: true
19 default: 'minor'
20 changelog_text:
21 description: 'Input the changes you''d like to add to the changelogs. Your text should be encapsulated in "''s with line feeds represented by literal \n''s. ie. "This is the first change\nThis is the second change"'
22 required: true
23 default: ''
24 update_news:
25 description: 'Update news in addon.xml.in? [true|false]'
26 required: true
27 default: 'true'
28 add_date:
29 description: 'Add date to version number in changelog and news. ie. "v1.0.1 (2021-7-17)" [true|false]'
30 required: true
31 default: 'false'
32
33 jobs:
34 default:
35 runs-on: ubuntu-latest
36 name: Changelog and Release
37
38 steps:
39
40 # Checkout the current repository into a directory (repositories name)
41 - name: Checkout Repository
42 uses: actions/checkout@v4
43 with:
44 fetch-depth: 0
45 path: ${{ github.event.repository.name }}
46
47 # Checkout the required scripts from xbmc/binary-addon-scripts into the 'scripts' directory
48 - name: Checkout Scripts
49 uses: actions/checkout@v4
50 with:
51 fetch-depth: 0
52 repository: xbmc/binary-addon-scripts
53 path: scripts
54
55 # Install all dependencies required by the following steps
56 # - libxml2-utils, xmlstarlet: reading news and version from addon.xml.in
57 - name: Install dependencies
58 run: |
59 sudo apt-get update
60 sudo apt-get install libxml2-utils xmlstarlet
61
62 # Setup python version 3.9
63 - name: Set up Python
64 uses: actions/setup-python@v5
65 with:
66 python-version: '3.9'
67
68 # Run the python script to increment the version, changelog and news
69 - name: Increment version and update changelogs
70 run: |
71 arguments=
72 if [[ ${{ github.event.inputs.update_news }} == true ]] ;
73 then
74 arguments=$(echo $arguments && echo --update-news)
75 fi
76 if [[ ${{ github.event.inputs.add_date }} == true ]] ;
77 then
78 arguments=$(echo $arguments && echo --add-date)
79 fi
80 python3 ../scripts/changelog_and_release.py ${{ github.event.inputs.version_type }} ${{ github.event.inputs.changelog_text }} $arguments
81 working-directory: ${{ github.event.repository.name }}
82
83 # Create the variables required by the following steps
84 # - steps.required-variables.outputs.changes: latest entry in the changelog.txt (if exists), or addon.xml.in news element
85 # - steps.required-variables.outputs.version: version element from addon.xml.in
86 # - steps.required-variables.outputs.branch: branch of the triggering ref
87 # - steps.required-variables.outputs.today: today's date in format '%Y-%m-%d'
88 # Note: we use a random EOF for 'changes' as is best practice for for multiline variables
89 - name: Get required variables
90 id: required-variables
91 run: |
92 changes=$(cat "$(find . -name changelog.txt)" | awk -v RS= 'NR==1')
93 if [ -z "$changes" ] ;
94 then
95 changes=$(xmlstarlet fo -R "$(find . -name addon.xml.in)" | xmlstarlet sel -t -v 'string(/addon/extension/news)' | awk -v RS= 'NR==1')
96 fi
97 EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
98 echo "changes<<$EOF" >> $GITHUB_OUTPUT
99 echo "$changes" >> $GITHUB_OUTPUT
100 echo "$EOF" >> $GITHUB_OUTPUT
101 version=$(xmlstarlet fo -R "$(find . -name addon.xml.in)" | xmlstarlet sel -t -v 'string(/addon/@version)')
102 echo "version=$version" >> $GITHUB_OUTPUT
103 branch=$(echo ${GITHUB_REF#refs/heads/})
104 echo "branch=$branch" >> $GITHUB_OUTPUT
105 echo "today=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
106 working-directory: ${{ github.event.repository.name }}
107
108 # Create a commit of the incremented version and changelog, news changes
109 # Commit message (add_date=false): changelog and version v{steps.required-variables.outputs.version}
110 # Commit message (add_date=true): changelog and version v{steps.required-variables.outputs.version} ({steps.required-variables.outputs.today})
111 - name: Commit changes
112 run: |
113 git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
114 git config --local user.name "github-actions[bot]"
115 commit_message="changelog and version v${{ steps.required-variables.outputs.version }}"
116 if [[ ${{ github.event.inputs.add_date }} == true ]] ;
117 then
118 commit_message="$commit_message (${{ steps.required-variables.outputs.today }})"
119 fi
120 git commit -m "$commit_message" -a
121 working-directory: ${{ github.event.repository.name }}
122
123 # Push the commit(s) created above to the triggering branch
124 - name: Push changes
125 uses: ad-m/github-push-action@master
126 with:
127 branch: ${{ github.ref }}
128 directory: ${{ github.event.repository.name }}
129
130 # Sleep for 60 seconds to allow for any delays in the push
131 - name: Sleep for 60 seconds
132 run: sleep 60s
133 shell: bash
134
135 # Create a release at {steps.required-variables.outputs.branch}
136 # - tag and release name format: {steps.required-variables.outputs.version}-{steps.required-variables.outputs.branch} ie. 21.0.0-Omega
137 # - release body: {steps.required-variables.outputs.changes}
138 - name: Create Release
139 id: create-release
140 uses: actions/create-release@v1
141 env:
142 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
143 with:
144 tag_name: ${{ steps.required-variables.outputs.version }}-${{ steps.required-variables.outputs.branch }}
145 release_name: ${{ steps.required-variables.outputs.version }}-${{ steps.required-variables.outputs.branch }}
146 body: ${{ steps.required-variables.outputs.changes }}
147 draft: false
148 prerelease: false
149 commitish: ${{ steps.required-variables.outputs.branch }}