diff --git a/.github/workflows/container.yaml b/.github/workflows/container.yaml index 86ee8692d..4975647e9 100644 --- a/.github/workflows/container.yaml +++ b/.github/workflows/container.yaml @@ -5,8 +5,7 @@ on: branches: - "develop" - "main" - tags: - - "v*" + - "releases/**/*" pull_request: branches: - "develop" @@ -60,6 +59,8 @@ jobs: outputs: continue: ${{ steps.check.outputs.continue }} + type: ${{ steps.check.outputs.type }} + version: ${{ steps.check.outputs.version }} steps: - id: check @@ -67,12 +68,24 @@ jobs: run: | if [[ "${{ github.repository }}" == "torrust/torrust-tracker" ]]; then if [[ "${{ github.event_name }}" == "push" ]]; then - if [[ "${{ github.ref }}" == "refs/heads/main" || - "${{ github.ref }}" == "refs/heads/develop" || - "${{ github.ref }}" =~ ^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$ ]]; then + if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then + + echo "type=development" >> $GITHUB_OUTPUT + echo "continue=true" >> $GITHUB_OUTPUT + + fi + if [[ "${{ github.ref }}" == "refs/heads/develop" ]]; then + + echo "type=development" >> $GITHUB_OUTPUT + echo "continue=true" >> $GITHUB_OUTPUT + + if [[ "${{ github.ref }}" =~ ^(refs\/heads\/releases\/)(v)(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$ ]]; then + + version=$(echo "${{ github.ref }}" | sed -n -E 's/^(refs\/heads\/releases\/)//p') + echo "version=$version" >> $GITHUB_OUTPUT + echo "type=release" >> $GITHUB_OUTPUT + echo "continue=true" >> $GITHUB_OUTPUT - echo "Context is torrust/torrust-tracker, and push is: main, develop, docker, or a tag with a semantic version" - echo "continue=true" >> $GITHUB_OUTPUT fi fi fi @@ -103,17 +116,28 @@ jobs: runs-on: ubuntu-latest steps: - - id: meta - name: Docker meta + - id: meta_development + if: needs.secrets.check.type == 'development' + name: Docker Meta (development) uses: docker/metadata-action@v4 with: images: | "${{ secrets.DOCKER_HUB_USERNAME }}/${{secrets.DOCKER_HUB_REPOSITORY_NAME }}" tags: | type=ref,event=branch - type=ref,event=pr - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} + + - id: meta_release + if: needs.secrets.check.type == 'release' + name: Docker Meta (release) + uses: docker/metadata-action@v4 + with: + images: | + "${{ secrets.DOCKER_HUB_USERNAME }}/${{secrets.DOCKER_HUB_REPOSITORY_NAME }}" + tags: | + type=semver,value=${{ needs.secrets.check.version }},pattern={{raw}} + type=semver,value=${{ needs.secrets.check.version }},pattern={{version}} + type=semver,value=${{ needs.secrets.check.version }},pattern=v{{major}} + type=semver,value=${{ needs.secrets.check.version }},pattern={{major}}.{{minor}} - id: login name: Login to Docker Hub diff --git a/.github/workflows/deployment.yaml b/.github/workflows/deployment.yaml index 73c024143..e3b042fd5 100644 --- a/.github/workflows/deployment.yaml +++ b/.github/workflows/deployment.yaml @@ -2,8 +2,8 @@ name: Deployment on: push: - tags: - - "v*" + branches: + - "releases/**/*" jobs: secrets: @@ -18,8 +18,8 @@ jobs: - id: check name: Check env: - CRATES_TOKEN: "${{ secrets.CRATES_TOKEN }}" - if: "${{ env.CRATES_TOKEN != '' }}" + CARGO_REGISTRY_TOKEN: "${{ secrets.CARGO_REGISTRY_TOKEN }}" + if: "${{ env.CARGO_REGISTRY_TOKEN != '' }}" run: echo "continue=true" >> $GITHUB_OUTPUT test: @@ -66,7 +66,7 @@ jobs: toolchain: stable env: - CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_TOKEN }} + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} - id: publish name: Publish Crates