Skip to content

Commit ac4ff70

Browse files
authored
[patch] feat: Added .github/workflows (#5)
1 parent 84094b1 commit ac4ff70

15 files changed

Lines changed: 313 additions & 2 deletions

File tree

.github/workflows/release.yml

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
get-plugins:
8+
runs-on: ubuntu-latest
9+
outputs:
10+
plugins: ${{ steps.set-matrix.outputs.plugins_json }}
11+
steps:
12+
- uses: actions/checkout@v6
13+
with:
14+
fetch-depth: 0
15+
16+
- name: Get changed plugins
17+
id: set-matrix
18+
env:
19+
DIFF_BASE: ${{ github.base_ref }}
20+
run: |
21+
plugins=$(jq -c '[.plugins[].name]' plugins.json)
22+
echo "Changed plugins: $plugins"
23+
echo "plugins_json=$plugins" >> $GITHUB_OUTPUT
24+
25+
create-plugin-release:
26+
needs: get-plugins
27+
runs-on: ubuntu-latest
28+
outputs:
29+
plugin_name: ${{ matrix.plugin }}
30+
upload_url: ${{ steps.create_release.outputs.upload_url }}
31+
permissions:
32+
contents: write
33+
pull-requests: write
34+
strategy:
35+
matrix:
36+
plugin: ${{ fromJSON(needs.get-plugins.outputs.plugins) }}
37+
steps:
38+
- uses: actions/checkout@v6
39+
with:
40+
fetch-depth: 0
41+
- name: Fetch last tag
42+
run: |
43+
git fetch --tags
44+
45+
LATEST_TAG=$(git describe --abbrev=0 --tags --match "${{ matrix.plugin }}/*" 2>/dev/null || true)
46+
if [ -z "$LATEST_TAG" ]; then
47+
LATEST_TAG=$(git rev-list --max-parents=0 HEAD)
48+
LATEST_VERSION="0.0.0"
49+
echo "Latest tag not found. The first commit of the repository will be used to search for plugin changelogs: $LATEST_TAG"
50+
51+
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV
52+
echo "LATEST_VERSION=$LATEST_VERSION" >> $GITHUB_ENV
53+
exit 0
54+
fi
55+
echo $LATEST_TAG
56+
57+
LATEST_VERSION=$(echo "$LATEST_TAG" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')
58+
if [ -n "$LATEST_VERSION" ]; then
59+
LATEST_VERSION="${LATEST_VERSION}"
60+
else
61+
echo "Failed to extract version from tag: $LATEST_TAG" >&2; exit 1;
62+
fi
63+
64+
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV
65+
echo "LATEST_VERSION=$LATEST_VERSION" >> $GITHUB_ENV
66+
- name: Calculate new version
67+
id: new-version
68+
if: env.LATEST_TAG != ''
69+
run: |
70+
LATEST_TAG="${{ env.LATEST_TAG }}"
71+
LATEST_VERSION="${{ env.LATEST_VERSION }}"
72+
73+
set +e
74+
ALL_MESSAGES=$(git log "$LATEST_TAG"..HEAD --format=%B -- ${{ matrix.plugin }} | grep -E "\[(patch|minor|major)\] (feat|fix|refactor): .*")
75+
set -e
76+
77+
if [ -z "$ALL_MESSAGES" ]; then
78+
echo "ALL_MESSAGES is empty. The plugin has not had any changes." >&2;
79+
exit 0
80+
fi
81+
82+
echo "ALL_MESSAGES=$ALL_MESSAGES"
83+
84+
chmod +x ./scripts/helpers/incr_semver.bash
85+
86+
new_patch=""
87+
if [[ "$ALL_MESSAGES" == *"[major]"* ]]; then
88+
new_patch=$(./scripts/helpers/incr_semver.bash "$LATEST_VERSION" major)
89+
echo "NEW_BUMP_TYPE=major" >> $GITHUB_ENV
90+
elif [[ "$ALL_MESSAGES" == *"[minor]"* ]]; then
91+
new_patch=$(./scripts/helpers/incr_semver.bash "$LATEST_VERSION" minor)
92+
echo "NEW_BUMP_TYPE=minor" >> $GITHUB_ENV
93+
else
94+
new_patch=$(./scripts/helpers/incr_semver.bash "$LATEST_VERSION" patch)
95+
echo "NEW_BUMP_TYPE=patch" >> $GITHUB_ENV
96+
fi
97+
98+
echo "NEW_VERSION=$new_patch" >> $GITHUB_ENV
99+
100+
echo "CHANGELOG<<EOF" >> $GITHUB_ENV
101+
echo "$ALL_MESSAGES" >> $GITHUB_ENV
102+
echo "EOF" >> $GITHUB_ENV
103+
104+
- name: Create Release
105+
if: env.NEW_VERSION != ''
106+
id: create_release
107+
uses: actions/create-release@v1.1.4
108+
env:
109+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
110+
with:
111+
tag_name: ${{ matrix.plugin }}/${{ env.NEW_VERSION }}
112+
release_name: ${{ matrix.plugin }}/${{ env.NEW_VERSION }}
113+
body: ${{ env.CHANGELOG }}
114+
draft: true
115+
prerelease: false
116+
- name: Write upload_url
117+
env:
118+
plugin_upload_url: ${{ steps.create_release.outputs.upload_url }}
119+
run: echo $plugin_upload_url > plugin_upload_url
120+
- name: Produce Artifact
121+
uses: actions/upload-artifact@v4
122+
with:
123+
name: ${{ matrix.plugin }}
124+
path: plugin_upload_url
125+
126+
archive-plugin:
127+
needs:
128+
- get-plugins
129+
- create-plugin-release
130+
runs-on: ${{ matrix.os }}
131+
permissions:
132+
contents: write
133+
pull-requests: write
134+
strategy:
135+
matrix:
136+
os: [macos-26, ubuntu-latest]
137+
plugin: ${{ fromJSON(needs.get-plugins.outputs.plugins) }}
138+
steps:
139+
- name: Retrieve Upload Url
140+
uses: actions/download-artifact@v4
141+
with:
142+
name: ${{ matrix.plugin }}
143+
- name: Get plugin_upload_url
144+
run: |
145+
echo $(cat plugin_upload_url)
146+
echo "PLUGIN_UPLOAD_URL=$(cat plugin_upload_url)" >> $GITHUB_ENV
147+
- uses: actions/checkout@v6
148+
if: env.PLUGIN_UPLOAD_URL != ''
149+
- uses: jdx/mise-action@v2
150+
if: env.PLUGIN_UPLOAD_URL != ''
151+
- name: Archive plugin ${{ matrix.plugin }}
152+
if: env.PLUGIN_UPLOAD_URL != ''
153+
run: |
154+
PLUGIN_NAME=${{ matrix.plugin }}
155+
geko plugin archive --path $PLUGIN_NAME
156+
if [[ ${{ matrix.os }} == "ubuntu-latest" ]]; then
157+
ARCH="x86_64"
158+
find "$PLUGIN_NAME" -type f -iname "$PLUGIN_NAME.linux.$ARCH.geko-plugin.zip" -exec cp -v {} "$ARCH.linux-plugin.zip" \;
159+
echo "ARCHIVE_PATH=$ARCH.linux-plugin.zip" >> $GITHUB_ENV
160+
echo "ASSET_NAME=$PLUGIN_NAME.linux.$ARCH.geko-plugin.zip" >> $GITHUB_ENV
161+
else
162+
echo "ARCHIVE_PATH=$PLUGIN_NAME/$PLUGIN_NAME.macos.geko-plugin.zip" >> $GITHUB_ENV
163+
echo "ASSET_NAME=$PLUGIN_NAME.macos.geko-plugin.zip" >> $GITHUB_ENV
164+
fi
165+
- name: Upload release binary
166+
if: env.PLUGIN_UPLOAD_URL != ''
167+
uses: actions/upload-release-asset@v1.0.2
168+
env:
169+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
170+
with:
171+
upload_url: ${{ env.PLUGIN_UPLOAD_URL }}
172+
asset_path: ${{ env.ARCHIVE_PATH }}
173+
asset_name: ${{ env.ASSET_NAME }}
174+
asset_content_type: application/json

.github/workflows/test.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Test
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
get-changed-plugins:
13+
runs-on: ubuntu-latest
14+
outputs:
15+
plugins: ${{ steps.set-matrix.outputs.plugins_json }}
16+
steps:
17+
- uses: actions/checkout@v6
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Get changed plugins
22+
id: set-matrix
23+
env:
24+
DIFF_BASE: ${{ github.base_ref }}
25+
run: |
26+
git fetch origin $DIFF_BASE
27+
chmod +x ./scripts/helpers/changed_plugins.bash
28+
changed=$(./scripts/helpers/changed_plugins.bash)
29+
echo "Changed plugins: $changed"
30+
echo "plugins_json=$changed" >> $GITHUB_OUTPUT
31+
32+
test-plugins:
33+
needs: get-changed-plugins
34+
runs-on: ${{ matrix.os }}
35+
strategy:
36+
matrix:
37+
plugin: ${{ fromJSON(needs.get-changed-plugins.outputs.plugins) }}
38+
os: [macos-26, ubuntu-latest]
39+
steps:
40+
- uses: actions/checkout@v6
41+
- uses: jdx/mise-action@v2
42+
- name: Run tests for plugin
43+
run: |
44+
echo "Testing plugin ${{ matrix.plugin }}"
45+
geko plugin test --path ${{ matrix.plugin }}

ExecutablePluginExample/Package.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,11 @@ let package = Package(
1818
name: "ExampleTarget",
1919
dependencies: []
2020
),
21+
.testTarget(
22+
name: "ExecutablePluginExampleTests",
23+
dependencies: [
24+
"ExampleTarget"
25+
]
26+
)
2127
]
22-
)
28+
)

ExecutablePluginExample/Plugin.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import ProjectDescription
22

33
let plugin = Plugin(
4-
name: "GekoPlugin",
4+
name: "ExecutablePluginExample",
55
executables: [
66
ExecutablePlugin(name: "ExampleGekoExecutable")
77
]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Foundation
2+
import XCTest
3+
@testable import ExampleTarget
4+
5+
final class ExampleTargetTests: XCTestCase {
6+
func test_example() async throws {
7+
XCTAssert(true)
8+
}
9+
}
File renamed without changes.

WorkspaceMapperPluginExample/Package.swift renamed to WorkspaceMapperExample/Package.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ let package = Package(
3030
.product(name: "ProjectDescription", package: "project-description"),
3131
],
3232
path: "ProjectDescriptionHelpers"
33+
),
34+
.testTarget(
35+
name: "WorkspaceMapperExampleTests",
36+
dependencies: [
37+
"WorkspaceMapperExample"
38+
]
3339
)
3440
]
3541
)

WorkspaceMapperPluginExample/ProjectDescriptionHelpers/SomeStruct.swift renamed to WorkspaceMapperExample/ProjectDescriptionHelpers/SomeStruct.swift

File renamed without changes.

WorkspaceMapperPluginExample/Sources/WorkspaceMapperExample/WorkspaceMapperExample.swift renamed to WorkspaceMapperExample/Sources/WorkspaceMapperExample/WorkspaceMapperExample.swift

File renamed without changes.

0 commit comments

Comments
 (0)