Skip to content

Commit

Permalink
Added github action
Browse files Browse the repository at this point in the history
Signed-off-by: James Turnbull <[email protected]>
  • Loading branch information
jamtur01 committed Aug 27, 2024
1 parent cdbd267 commit bdb31bf
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 1 deletion.
1 change: 0 additions & 1 deletion .github

This file was deleted.

100 changes: 100 additions & 0 deletions .github/workflows/build-and-release.yml
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 }}

0 comments on commit bdb31bf

Please sign in to comment.