diff --git a/.github/workflows/build-docker.yaml b/.github/workflows/build-docker.yaml index 8c5a3b0..86aaf72 100644 --- a/.github/workflows/build-docker.yaml +++ b/.github/workflows/build-docker.yaml @@ -1,4 +1,4 @@ -name: Build +name: Create and publish a Docker image on: workflow_run: @@ -8,12 +8,21 @@ on: - completed branches: - main + push: + tags: + - '**' env: REGISTRY: ghcr.io IMAGE_NAME: accenture/federated-catalogue-viewer - + IMAGE_TAG: '' jobs: + generate-next-release-version: + if: ${{ github.ref_type == 'branch' }} + uses: ./.github/workflows/semantic-release.yaml + with: + dry-run: true + build-and-push-image: runs-on: ubuntu-latest @@ -31,6 +40,15 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 + - name: Determine Image Tag + if: ${{ github.ref_type == 'branch' }} + run: | + echo \"IMAGE_TAG=${{env.NEXT_RELEASE_VERSION}}-pre-release-$(git rev-parse --short ${{ github.sha }})\" >> $GITHUB_ENV + - name: Determine Image Tag + if: ${{ github.ref_type == 'tag' }} + run: | + echo \"IMAGE_TAG=${{github.ref_name}}\" >> $GITHUB_ENV + - name: Log in to the Container registry uses: docker/login-action@v3 with: @@ -44,4 +62,6 @@ jobs: platforms: linux/amd64,linux/arm64 context: . push: true - tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest + tags: | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..dc8dc70 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,7 @@ +name: Release + +on: workflow_dispatch + +jobs: + create-release: + uses: ./.github/workflows/semantic-release.yaml diff --git a/.github/workflows/semantic-release.yaml b/.github/workflows/semantic-release.yaml new file mode 100644 index 0000000..e64c43c --- /dev/null +++ b/.github/workflows/semantic-release.yaml @@ -0,0 +1,38 @@ +name: Create Release +on: + workflow_call: + inputs: + dry-run: + default: false + type: boolean + +permissions: + contents: read + +jobs: + release: + name: Release + runs-on: ubuntu-latest + permissions: + contents: write # to be able to publish a GitHub release + issues: write # to be able to comment on released issues + pull-requests: write # to be able to comment on released pull requests + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: 'lts/*' + + - name: Install Dependencies + run: npm install @semantic-release/exec conventional-changelog-conventionalcommits -D + + - name: Determine next Version + id: determine-next-version + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + npx semantic-release --dry-run ${{ inputs.dry-run }} diff --git a/.releaserc.json b/.releaserc.json new file mode 100644 index 0000000..b725489 --- /dev/null +++ b/.releaserc.json @@ -0,0 +1,31 @@ +{ + "plugins": [ + [ + "@semantic-release/commit-analyzer", + { + "preset": "conventionalcommits", + "releaseRules": [ + { "breaking": true, "release": "major" }, + { "revert": true, "release": "patch" }, + { "type": "build", "release": "patch" }, + { "type": "docs", "release": "patch" }, + { "type": "feat", "release": "minor" }, + { "type": "fix", "release": "patch" }, + { "type": "perf", "release": "patch" }, + { "type": "data", "release": "patch" }, + { "type": "explore", "release": "patch" }, + { "type": "result", "release": "patch" }, + { "type": "refactor", "release": "patch" } + ] + } + ], + [ + "@semantic-release/exec", + { + "verifyReleaseCmd": "echo \"NEXT_RELEASE_VERSION=${nextRelease.version}\" >> $GITHUB_ENV" + } + ], + "@semantic-release/github" + ], + "branches": ["main"] +}