-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: James Turnbull <[email protected]>
- Loading branch information
Showing
2 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
name: Build, Tag, and Release Hammerspoon Spoon | ||
|
||
permissions: | ||
contents: write | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
outputs: | ||
spoon_name: ${{ steps.spoon_name.outputs.spoon_name }} | ||
tag_name: ${{ steps.tag_name.outputs.tag_name }} | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Get Spoon Name | ||
id: spoon_name | ||
run: | | ||
spoon_name=$(grep -Eo 'obj.name\s*=\s*"[^"]+"' init.lua | cut -d'"' -f2) | ||
if [ -z "$spoon_name" ]; then | ||
echo "Spoon name not found, failing the job." | ||
exit 1 | ||
fi | ||
echo "spoon_name=${spoon_name}" >> $GITHUB_OUTPUT | ||
- name: Build the Spoon | ||
run: | | ||
mkdir -p dist | ||
zip -r dist/${{ steps.spoon_name.outputs.spoon_name }}.spoon.zip . -x ".git*" ".github*" "dist/*" | ||
- name: List Files in dist/ for Debugging | ||
run: ls -l dist/ | ||
|
||
- name: Upload the Spoon Artifact | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: ${{ steps.spoon_name.outputs.spoon_name }}.spoon.zip | ||
path: dist/${{ steps.spoon_name.outputs.spoon_name }}.spoon.zip | ||
|
||
- name: Get the Git SHA | ||
id: git-sha | ||
run: | | ||
sha=$(git rev-parse --short HEAD) | ||
echo "sha=${sha}" >> $GITHUB_OUTPUT | ||
- name: Extract obj.version from spoon | ||
id: version | ||
run: | | ||
version=$(grep -Eo 'obj.version\s*=\s*"[^"]+"' init.lua | cut -d'"' -f2 || echo "") | ||
echo "version=${version}" >> $GITHUB_OUTPUT | ||
- name: Determine Tag Name | ||
id: tag_name | ||
run: | | ||
datetime=$(date +"%Y%m%d-%H%M%S") | ||
if [ -n "${{ steps.version.outputs.version }}" ]; then | ||
tag_name="v${{ steps.version.outputs.version }}-${datetime}" | ||
else | ||
tag_name="${datetime}" | ||
fi | ||
echo "tag_name=${tag_name}" >> $GITHUB_OUTPUT | ||
- name: Create and Push Git Tag | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
git config user.name "GitHub Actions" | ||
git config user.email "[email protected]" | ||
git tag -a ${{ steps.tag_name.outputs.tag_name }} -m "Release ${{ steps.tag_name.outputs.tag_name }}" | ||
git push origin ${{ steps.tag_name.outputs.tag_name }} | ||
release: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Download Spoon Artifact | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: ${{ needs.build.outputs.spoon_name }}.spoon.zip | ||
|
||
- name: List Files in dist/ for Debugging in Release Job | ||
run: ls -l . | ||
|
||
- name: Create GitHub Release | ||
uses: softprops/action-gh-release@v2 | ||
with: | ||
tag_name: ${{ needs.build.outputs.tag_name }} # Use the tag created in the build step | ||
name: ${{ needs.build.outputs.tag_name }} # Release name based on the tag | ||
files: ${{ needs.build.outputs.spoon_name }}.spoon.zip | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |