Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: upload rockspec to LuaRocks on tag push #106

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 50 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,22 @@ jobs:
runtestArgs: "LUA_INCLUDE_DIR=.lua/include/luajit-2.1"
runtestEnv: "SKIP_CMAKE=1"

# due to 'luarocks/gh-actions-lua@master' caching,
# keep 'runs-on' synced with 'runs-on' from
# 'upload' job below
runs-on: ubuntu-24.04

steps:
- uses: actions/checkout@master

- uses: leafo/gh-actions-lua@master
- uses: luarocks/gh-actions-lua@master
env:
CC: ${{ matrix.cc }}
with:
luaVersion: ${{ matrix.luaVersion }}
luaCompileFlags: CC=${{ matrix.cc }}

- uses: leafo/gh-actions-luarocks@master
- uses: luarocks/gh-actions-luarocks@master

- name: runtests.sh
env:
Expand Down Expand Up @@ -59,3 +62,48 @@ jobs:
run: |
luarocks make

upload:
name: Upload Rockspec

# due to 'luarocks/gh-actions-lua@master' caching,
# keep 'runs-on' synced with 'runs-on' from
# 'test' job above
runs-on: ubuntu-24.04

needs: test
if: ${{ github.repository == 'openresty/lua-cjson' && github.ref_type == 'tag' }}

steps:
- uses: actions/checkout@master
- uses: luarocks/gh-actions-lua@master
- uses: luarocks/gh-actions-luarocks@master

- name: Set environment variable to hold the rockspec name to be uploaded
run: |
rockspec=$(find *.rockspec | head -n1);
echo "ROCKSPEC=${rockspec}" >> "${{ github.env }}";

- name: Make sure that tags from GitHub and rockspec are equal
run: |
rockspec_tag=$(lua -e "dofile(arg[0]); io.write(source.tag);" -- "${{ env.ROCKSPEC }}");
github_tag="${{ github.ref_name }}";

if [[ "${rockspec_tag}" != "${github_tag}" ]];
then
echo -e "\e[31mTag mismatch\e[0m: GitHub tag (\e[33m${github_tag}\e[0m) != rockspec tag (\e[33m${rockspec_tag}\e[0m)";
exit 1;
fi;

- name: Install dependencies
run: |
sudo apt install -y libssl-dev;
luarocks install luasocket;
luarocks install luasec;

- name: Upload to LuaRocks
env:
UPLOAD_KEY: "${{ secrets.LUAROCKS_APIKEY }}"
run: |
echo -e "Uploading rockspec: \e[36m${{ env.ROCKSPEC }}\e[0m";

luarocks upload "${{ env.ROCKSPEC }}" "--temp-key" "$UPLOAD_KEY";