From 064bd6b373e1f6ad86af533d151261c57bdbdfb9 Mon Sep 17 00:00:00 2001 From: Skydust Date: Wed, 25 Dec 2024 15:44:15 +0100 Subject: [PATCH] First commit --- .gitignore | 1 + README.md | 2 ++ action.yml | 30 ++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 action.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..485dee6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea diff --git a/README.md b/README.md new file mode 100644 index 0000000..e0340ed --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# get-version + diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..e6bf532 --- /dev/null +++ b/action.yml @@ -0,0 +1,30 @@ +name: Retrieve version +description: Uses the tags and git commit to find a unique version and sets it as NEW_VERSION +author: Skydust + +runs: + using: composite + steps: + - name: Get commit version + run: | + if [[ "${{ github.ref }}" == refs/tags/* ]]; then + NEW_VERSION="${GITHUB_REF##refs/tags/}" + log_info "This is a tag push: $(yellow)${NEW_VERSION}" + else + log_info "This is a branch push: $(yellow)${GITHUB_REF##refs/heads/}" + + last_version="$(git describe --tags --match "v*" --abbrev=0 || echo "")" + if [[ -z "$last_version" ]]; then + last_version="v0.0.0" + fi + + calculatedSha="$(git rev-parse --short ${{ github.sha }})" + NEW_VERSION="${last_version}-${calculatedSha}" + fi + + # Removing the v + NEW_VERSION="${NEW_VERSION:1}" + + log_info "New version: $(yellow)${NEW_VERSION}" + log_info "Exported version in env var $(yellow)NEW_VERSION" + echo "NEW_VERSION=${NEW_VERSION}" >> $GITEA_ENV