-
-
Notifications
You must be signed in to change notification settings - Fork 38
159 lines (141 loc) · 5.35 KB
/
publish.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
name: Publish Library to PIO Registry
on:
workflow_dispatch:
inputs:
part_to_increment:
description: "Part to increment (1 for major, 2 for minor, 3 for patch)"
required: true
tag_version:
description: "Version to update if not incrementing"
required: false
permissions:
contents: write
jobs:
publish:
name: Prepare Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Update Version
env:
PART_TO_INCREMENT: ${{ github.event.inputs.part_to_increment }}
TAG_VERSION: ${{ github.event.inputs.tag_version }}
run: |
if [ -n "$TAG_VERSION" ]; then
UPDATED_VERSION=$TAG_VERSION
else
chmod +x version
./version "$PART_TO_INCREMENT"
UPDATED_VERSION=$(grep "version=" library.properties | cut -d'=' -f2)
fi
echo "UPDATED_VERSION=$UPDATED_VERSION" >> $GITHUB_ENV
- name: Check if tag exists
id: check_tag
uses: actions/github-script@v6
with:
script: |
const tag = '${{ env.UPDATED_VERSION }}';
const { data: tags } = await github.rest.repos.listTags({
owner: context.repo.owner,
repo: context.repo.repo
});
const tagExists = tags.some(t => t.name === tag);
core.setOutput('tag_exists', tagExists);
- name: Commit changes
if: steps.check_tag.outputs.tag_exists == 'false'
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git remote set-url origin https://x-access-token:${{ secrets.GH_PAT }}@github.com/forntoh/LcdMenu.git
git add .
git commit -m "Update version to $UPDATED_VERSION"
git push origin ${{ github.ref }}
- name: Create Tag
if: steps.check_tag.outputs.tag_exists == 'false'
run: |
git tag -a "${{ env.UPDATED_VERSION }}" -m "Tagging version ${{ env.UPDATED_VERSION }}"
git push origin "${{ env.UPDATED_VERSION }}" --force
- name: Install dependencies
if: steps.check_tag.outputs.tag_exists == 'false'
run: |
python -m pip install --upgrade pip
pip install click
pip install --upgrade platformio
- name: Login to PlatformIO
if: steps.check_tag.outputs.tag_exists == 'false'
run: |
pio account login -u "${{ secrets.PIO_USERNAME }}" -p "${{ secrets.PIO_PASSWORD }}"
- name: Publish to PlatformIO
if: steps.check_tag.outputs.tag_exists == 'false'
id: publish
run: yes y | pio pkg publish
continue-on-error: true
- name: Revert push and delete tag if publish fails
if: failure()
run: |
git reset --hard HEAD~1
git push origin +HEAD
git tag -d ${{ env.UPDATED_VERSION }}
git push origin :refs/tags/${{ env.UPDATED_VERSION }}
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: "14"
- name: Install @actions/github
run: npm install @actions/github
- name: Generate Release Notes
id: generate_release_notes
uses: actions/github-script@v6
env:
CURRENT_TAG: ${{ env.UPDATED_VERSION }}
BRANCH_REF: ${{ github.ref }}
with:
script: |
const generateReleaseNotes = require('.scripts/release_notes.js');
const releaseNotes = await generateReleaseNotes(github, context);
core.setOutput('release_notes', releaseNotes);
- name: Create GitHub Release
if: steps.check_tag.outputs.tag_exists == 'false'
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.UPDATED_VERSION }}
name: LcdMenu v${{ env.UPDATED_VERSION }}
draft: false
prerelease: false
generate_release_notes: false
make_latest: true
target_commitish: ${{ github.sha }}
token: ${{ secrets.GH_PAT }}
body: ${{ steps.generate_release_notes.outputs.release_notes }}
- name: Update GitHub Release
if: steps.check_tag.outputs.tag_exists == 'true'
uses: actions/github-script@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
script: |
const { data: releases } = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo
});
const release = releases.find(r => r.tag_name === '${{ env.UPDATED_VERSION }}');
if (release) {
console.log('Updating release notes for release', release.id);
await github.rest.repos.updateRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: release.id,
body: `${{ steps.generate_release_notes.outputs.release_notes }}`
});
} else {
console.log('Release not found');
}