From 80c423babe6bc9a91869674110e8b74a2eb588c2 Mon Sep 17 00:00:00 2001 From: Zeping Bai Date: Fri, 9 Aug 2024 17:13:49 +0800 Subject: [PATCH] ci: add auto release workflow (#2) --- .github/workflows/release.yml | 61 +++++++++++++++++++++++++++ .version | 1 + Makefile | 9 ++-- lua-resty-aws-dev-1.rockspec.template | 10 ++--- test2.lua | 48 --------------------- upload.sh | 4 +- 6 files changed, 74 insertions(+), 59 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 .version delete mode 100644 test2.lua diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..5caaec6 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,61 @@ +name: Release + +on: + push: + branches: [main] + +jobs: + release: + name: Release + runs-on: ubuntu-latest + if: "startsWith(github.event.head_commit.message, 'feat: release v')" + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install Lua + uses: leafo/gh-actions-lua@v8 + + - name: Install Luarocks + uses: leafo/gh-actions-luarocks@v4 + + - name: Extract release name + id: release_env + shell: bash + env: + MESSAGE: ${{ github.event.head_commit.message }} + run: | + title="${MESSAGE}" + re="^feat: release v*(\S+)" + if [[ $title =~ $re ]]; then + v=v${BASH_REMATCH[1]} + echo "##[set-output name=version;]${v}" + echo "##[set-output name=version_withou_v;]${BASH_REMATCH[1]}" + else + echo "commit format is not correct" + exit 1 + fi + + - name: Check dot version + shell: bash + run: | + if [ "${{ steps.release_env.outputs.version_withou_v }}" != "$(cat .version)" ]; then + echo "VERSION '${{ steps.release_env.outputs.version_withou_v }}' does not match the dot version file '$(cat .version)'" + exit 1 + fi + + - name: Create Release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ steps.release_env.outputs.version_withou_v }} + release_name: ${{ steps.release_env.outputs.version }} + draft: false + prerelease: false + + - name: Upload to luarocks + env: + VERSION: ${{ steps.release_env.outputs.version_withou_v }} + APIKEY: ${{ secrets.LUAROCKS_TOKEN }} + run: make upload diff --git a/.version b/.version new file mode 100644 index 0000000..8af85be --- /dev/null +++ b/.version @@ -0,0 +1 @@ +1.5.3 diff --git a/Makefile b/Makefile index 5ba84f7..b39e5fe 100644 --- a/Makefile +++ b/Makefile @@ -34,15 +34,16 @@ $(target_rock): [ -n "$$VERSION" ] || { echo VERSION not set; exit 1; } -@rm -rf /tmp/random_dir_2cs4f0tghRT mkdir /tmp/random_dir_2cs4f0tghRT - cd /tmp/random_dir_2cs4f0tghRT; git clone https://github.com/kong/lua-resty-aws.git + cd /tmp/random_dir_2cs4f0tghRT; git clone https://github.com/api7/lua-resty-aws.git cd /tmp/random_dir_2cs4f0tghRT/lua-resty-aws; if [ ! "${VERSION}" = "dev" ]; then git checkout ${VERSION}; fi cd /tmp/random_dir_2cs4f0tghRT/lua-resty-aws; make dev cd /tmp/random_dir_2cs4f0tghRT; zip -r lua-resty-aws-${VERSION}-1.src.rock lua-resty-aws cd /tmp/random_dir_2cs4f0tghRT; cat lua-resty-aws/lua-resty-aws-dev-1.rockspec | sed "s/package_version = \"dev\"/package_version = \"${VERSION}\"/" > lua-resty-aws-${VERSION}-1.rockspec cd /tmp/random_dir_2cs4f0tghRT; zip -r lua-resty-aws-${VERSION}-1.src.rock lua-resty-aws-${VERSION}-1.rockspec - mv /tmp/random_dir_2cs4f0tghRT/lua-resty-aws-${VERSION}-1.src.rock ./ - -@rm lua-resty-aws-${VERSION}-1.rockspec - mv /tmp/random_dir_2cs4f0tghRT/lua-resty-aws-${VERSION}-1.rockspec ./ + mv /tmp/random_dir_2cs4f0tghRT/lua-resty-aws-${VERSION}-1.src.rock ./api7-lua-resty-aws-${VERSION}-1.src.rock + -@rm api7-lua-resty-aws-${VERSION}-1.rockspec + mv /tmp/random_dir_2cs4f0tghRT/lua-resty-aws-${VERSION}-1.rockspec ./api7-lua-resty-aws-${VERSION}-1.rockspec + pack: $(target_rock) diff --git a/lua-resty-aws-dev-1.rockspec.template b/lua-resty-aws-dev-1.rockspec.template index ffb6f62..b18c857 100644 --- a/lua-resty-aws-dev-1.rockspec.template +++ b/lua-resty-aws-dev-1.rockspec.template @@ -1,8 +1,8 @@ -local package_name = "lua-resty-aws" +local package_name = "api7-lua-resty-aws" local package_version = "dev" local rockspec_revision = "1" -local github_account_name = "Kong" -local github_repo_name = package_name +local github_account_name = "api7" +local github_repo_name = "lua-resty-aws" local git_checkout = package_version == "dev" and "main" or package_version package = package_name @@ -10,7 +10,7 @@ version = package_version .. "-" .. rockspec_revision source = { url = "git://github.com/"..github_account_name.."/"..github_repo_name..".git", - branch = git_checkout + tag = git_checkout } description = { @@ -19,7 +19,7 @@ description = { AWS SDK generated from the same data as the AWS JavaScript SDK. ]], license = "Apache 2.0", - homepage = "https://"..github_account_name..".github.io/"..github_repo_name.."/topics/README.md.html" + homepage = "https://github.com/"..github_account_name.."/"..github_repo_name } dependencies = { diff --git a/test2.lua b/test2.lua deleted file mode 100644 index f65cf6d..0000000 --- a/test2.lua +++ /dev/null @@ -1,48 +0,0 @@ -setmetatable(_G, nil) -- disable global warnings - --- make sure we can use dev code -package.path = "./src/?.lua;./src/?/init.lua;"..package.path - --- quick debug dump function -local dump = function(...) - local t = { n = select("#", ...), ...} - if t.n == 1 and type(t[1]) == "table" then t = t[1] end - print(require("pl.pretty").write(t)) -end - - - - - -local AWS = require("resty.aws") -local aws = AWS() -local secretsmanager = aws:SecretsManager { region = "us-east-2" } - -dump(secretsmanager:getSecretValue { - SecretId = "arn:aws:secretsmanager:us-east-2:238406704566:secret:test2-HN1F1k", - VersionStage = "AWSCURRENT", -}) - - - ---[[ -local secret = assert(credentials.fetch_secret(creds, { - SecretId = "arn:aws:secretsmanager:us-east-2:238406704566:secret:test2-HN1F1k", -})) - -dump(secret) - -local secret = assert(credentials.fetch_secret(creds, { - SecretId = "arn:aws:secretsmanager:us-east-2:238406704566:secret:KEY_VALUE_test-IHwf2S", -})) - -dump(secret) - -local secret = assert(credentials.fetch_secret(creds, { - SecretId = "arn:aws:secretsmanager:us-east-2:238406704566:secret:test3_plain_text-PDPBwp", -})) - -dump(secret) ---]] - ---require "resty.credentials.aws.api" diff --git a/upload.sh b/upload.sh index 5ea7397..735a75c 100755 --- a/upload.sh +++ b/upload.sh @@ -7,8 +7,8 @@ LR_API_KEY=$2 #LR_API_KEY=INfSIgkuArccxH9zq9M7enqackTiYtgRM6c9l6Y4 -ROCK_FILE=lua-resty-aws-$ROCK_VERSION.src.rock -ROCKSPEC_FILE=lua-resty-aws-$ROCK_VERSION.rockspec +ROCK_FILE=api7-lua-resty-aws-$ROCK_VERSION.src.rock +ROCKSPEC_FILE=api7-lua-resty-aws-$ROCK_VERSION.rockspec if [ "$ROCK_VERSION" == "-1" ]; then echo "First argument (version) is missing."