Skip to content

Commit

Permalink
dev: use releases branch prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
da2ce7 committed Sep 10, 2023
1 parent f0ed5c0 commit bd971a6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 17 deletions.
48 changes: 36 additions & 12 deletions .github/workflows/container.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ on:
branches:
- "develop"
- "main"
tags:
- "v*"
- "releases/**/*"
pull_request:
branches:
- "develop"
Expand Down Expand Up @@ -60,19 +59,33 @@ jobs:

outputs:
continue: ${{ steps.check.outputs.continue }}
type: ${{ steps.check.outputs.type }}
version: ${{ steps.check.outputs.version }}

steps:
- id: check
name: Check Context
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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: Deployment

on:
push:
tags:
- "v*"
branches:
- "releases/**/*"

jobs:
secrets:
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bd971a6

Please sign in to comment.