From 390f69ff3be867585af2a97750e5112f76db0985 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joris=20Dugu=C3=A9?= Date: Sun, 10 Nov 2024 18:05:45 +0100 Subject: [PATCH] feat(ci): implement auto release for better and more faster --- .github/workflows/publish.yml | 49 +++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..eca4067 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,49 @@ +name: Publish and release +on: + push: + branches: + - master + - main +jobs: + publish: + runs-on: ubuntu-latest + + permissions: + contents: write + id-token: write + + steps: + - uses: actions/checkout@v4 + - name: Read version from composer.json + id: get_version + run: | + VERSION=$(cat composer.json | jq -r '.version') + echo "version=$VERSION" >> $GITHUB_ENV + echo "::set-output name=version::$VERSION" + - name: Check if tag exists + id: check_tag + run: | + TAG_EXISTS=$(git tag -l "${{ steps.get_version.outputs.version }}") + echo "tag_exists=$TAG_EXISTS" >> $GITHUB_ENV + echo "::set-output name=tag_exists::$TAG_EXISTS" + - name: Create GitHub Tag + if: steps.check_tag.outputs.tag_exists == '' + uses: actions/github-script@v7 + with: + script: | + const tag = `${process.env.version}`; + const latestCommitSha = context.sha; + await github.rest.git.createRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: `refs/tags/${tag}`, + sha: latestCommitSha, + }); + - name: Create a Release + if: steps.check_tag.outputs.tag_exists == '' + uses: elgohr/Github-Release-Action@v5 + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag: "${{ steps.get_version.outputs.version }}" + title: "${{ steps.get_version.outputs.version }}"