From 1748c8c22f042a8ace653b1549bd7686a0b8dc73 Mon Sep 17 00:00:00 2001 From: Martin Wimpress Date: Sun, 12 Jan 2025 23:24:42 +0000 Subject: [PATCH] refactor: simplify ci and make lua and luarocks setup consistent --- .github/workflows/ci.yml | 61 ++++++++--------------------------- .github/workflows/release.yml | 41 ++++++++++++++++------- 2 files changed, 43 insertions(+), 59 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 04903fa..99553ea 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,72 +9,39 @@ on: jobs: test: - name: Test and check ️✅ + name: Test and check ️🔎 runs-on: ubuntu-22.04 strategy: matrix: - include: - - lua-type: "lua" - lua-version: "5.1" - - lua-type: "lua" - lua-version: "5.2" - - lua-type: "lua" - lua-version: "5.3" - - lua-type: "lua" - lua-version: "5.4" - - lua-type: "luajit" - luajit-version: "2.0" - - lua-type: "luajit" - luajit-version: "2.1" - + lua-version: [ + "5.1", + "5.2", + "5.3", + "5.4", + "luajit" + ] steps: - uses: actions/checkout@v4 - - - name: Setup Python - uses: actions/setup-python@v5 + - uses: jkl1337/gh-actions-lua@v11 with: - python-version: '3.x' - - - name: Create and activate virtual environment - run: | - python -m venv venv - source venv/bin/activate - echo "VIRTUAL_ENV=$VIRTUAL_ENV" >> $GITHUB_ENV - echo "$VIRTUAL_ENV/bin" >> $GITHUB_PATH - - - name: Install hererocks - run: pip install hererocks - - - name: Setup Lua - run: | - mkdir -p lua_install - if [[ "${{ matrix.lua-type }}" == "lua" ]]; then - hererocks lua_install -r^ --lua=${{ matrix.lua-version }} - else - hererocks lua_install -r^ --luajit=${{ matrix.luajit-version }} - fi - echo "$PWD/lua_install/bin" >> $GITHUB_PATH - + luaVersion: "${{ matrix.lua-version }}" + - uses: jkl1337/gh-actions-luarocks@v5 + with: + luaRocksVersion: "3.11.1" - name: Install dependencies run: | luarocks install luacheck luarocks install busted luarocks install luacov - - name: Run tests and checks run: | luacheck --no-unused-args --std max+busted smiti18n spec busted --verbose --coverage - - name: Generate and show coverage report run: | luacov { - if [[ "${{ matrix.lua-type }}" == "lua" ]]; then - echo "# Test Coverage Summary - Lua ${{ matrix.lua-version }}" - else - echo "# Test Coverage Summary - LuaJIT ${{ matrix.luajit-version }}" - fi + echo "# Test Coverage Summary - ${{ matrix.lua-version }}" echo "" echo "| File | Hits | Missed | Coverage |" echo "|------|------|---------|----------|" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2f56a36..f40b0da 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,6 +11,9 @@ on: type: "string" required: true +env: + VERSION: ${{ github.event.inputs.tag || github.ref_name }} + jobs: version-check: if: github.event_name == 'push' || github.event.inputs.tag != '' @@ -26,12 +29,10 @@ jobs: echo "ERROR: rockspecs directory not found" exit 1 fi - - GIT_VERSION=$(echo ${{ github.ref_name }} | sed 's/^v//') - ROCKSPEC="rockspecs/smiti18n-${GIT_VERSION}-1.rockspec" - + VERSION=$(echo ${{ env.VERSION }} | sed 's/^v//') + ROCKSPEC="rockspecs/smiti18n-${VERSION}-1.rockspec" if [ ! -e "${ROCKSPEC}" ]; then - echo "ERROR: No rockspec found for version ${GIT_VERSION}" + echo "ERROR: No rockspec found for version ${VERSION}" echo "Expected: ${ROCKSPEC}" ls -la rockspecs/*.rockspec exit 1 @@ -47,13 +48,29 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then - echo "VERSION=${{ github.event.inputs.tag }}" >> $GITHUB_ENV - else - echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV - fi + VERSION=$(echo ${{ env.VERSION }} | sed 's/^v//') gh release create "${VERSION}" \ --draft=false \ --title "Release ${VERSION}" \ - --generate-notes \ - "rockspecs/smiti18n-${VERSION}-1.rockspec" + --generate-notes + + publish-rockspec: + needs: [publish-release] + name: "Publish Rockspec 🪨" + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + - name: "Setup Lua" + uses: jkl1337/gh-actions-lua@v11 + with: + luaVersion: "5.4" + - name: "Setup LuaRocks" + uses: jkl1337/gh-actions-luarocks@v5 + with: + luaRocksVersion: "3.11.1" + - name: "Upload rockspec" + env: + LUAROCKS_API_KEY: ${{ secrets.LUAROCKS_API_KEY }} + run: | + VERSION=$(echo ${{ env.VERSION }} | sed 's/^v//') + luarocks upload "rockspecs/smiti18n-${VERSION}-1.rockspec" --api-key=${LUAROCKS_API_KEY}