From a01d4248bf4b2891b2f5b064a481fceb0a317896 Mon Sep 17 00:00:00 2001 From: JCNoguera Date: Mon, 29 Jan 2024 20:48:29 +0100 Subject: [PATCH] feat: improve and add changelog to automatic deploy --- .github/workflows/build-images.reusable.yaml | 27 ++++------ .../create-draft-release.reusable.yaml | 49 +++++++++++++++++++ .github/workflows/release-production.yaml | 14 +++--- .github/workflows/release-staging.yaml | 12 +++-- 4 files changed, 72 insertions(+), 30 deletions(-) diff --git a/.github/workflows/build-images.reusable.yaml b/.github/workflows/build-images.reusable.yaml index f646dcd16..c4c0dac93 100644 --- a/.github/workflows/build-images.reusable.yaml +++ b/.github/workflows/build-images.reusable.yaml @@ -1,18 +1,18 @@ -name: Build and Push Images +name: Build and Push Docker Image on: workflow_call: inputs: - api_image_tags: + directory: required: true type: string - client_image_tags: + image_tags: required: true type: string jobs: - build-and-push-images: - name: Build and Push Docker Images + build-and-push-image: + name: Build and Push Docker Image runs-on: ubuntu-latest steps: - name: Checkout code @@ -32,20 +32,11 @@ jobs: username: ${{ secrets.IOTALEDGER_DOCKER_USERNAME }} password: ${{ secrets.IOTALEDGER_DOCKER_PASSWORD }} - - name: Build and push API Docker image + - name: Build and push Docker image for ${{ inputs.directory }} uses: docker/build-push-action@v2 with: - context: ./api - file: ./api/Dockerfile + context: ./${{ inputs.directory }} + file: ./${{ inputs.directory }}/Dockerfile push: true - tags: ${{ inputs.api_image_tags }} - no-cache: true - - - name: Build and push Client Docker image - uses: docker/build-push-action@v2 - with: - context: ./client - file: ./client/Dockerfile - push: true - tags: ${{ inputs.client_image_tags }} + tags: ${{ inputs.image_tags }} no-cache: true diff --git a/.github/workflows/create-draft-release.reusable.yaml b/.github/workflows/create-draft-release.reusable.yaml index 6d4d319c4..40dc71615 100644 --- a/.github/workflows/create-draft-release.reusable.yaml +++ b/.github/workflows/create-draft-release.reusable.yaml @@ -18,9 +18,58 @@ jobs: - name: Checkout uses: actions/checkout@v3 + - name: Prepare repository tags + run: | + if git rev-parse --is-shallow-repository | grep -q 'true'; then + git fetch --prune --unshallow --tags -f + else + git fetch --prune --tags -f + fi + + - name: Build changelog + id: build_changelog + run: | + echo "Building changelog..." + + # Create a changelog file with a header: + echo "# Changelog" > CHANGELOG.md + + # Check repository tags and the last tagged commit + n_tags=`git tag -l 'v*' --sort=-v:refname | wc -l` + prev_tag=`git tag -l 'v*' --sort=-v:refname | sed '2q;d'` + if [ $n_tags -eq 1 ]; then + last_commit=`git rev-list --max-parents=0 HEAD` + else + last_commit=`git rev-list -n 1 $prev_tag` + fi + + # Fill the changelog file with the commits since the last tag + # Set max tries to equal the maximum number of commits as protection + max_tries=`git rev-list --count HEAD` + i=0 + while [ `git rev-parse HEAD~$i` != $last_commit ] && [ $i -lt $((max_tries-1)) ] + do + echo '- ' `git show -s --format=%s HEAD~$i` >> CHANGELOG.md + i=$((i+1)) + done + + # Set the complete changelog url + echo >> CHANGELOG.md + compare="" + if [ $n_tags -eq 1 ]; then + compare=$last_commit + else + compare=$prev_tag + fi + compare="${compare}...`git tag -l 'v*' --sort=-v:refname | sed '1q;d'`" + echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/${compare}" >> CHANGELOG.md + + echo "Changelog built successfully." + - name: Create Draft Release uses: softprops/action-gh-release@v1 with: name: ${{ inputs.name }} tag_name: ${{ inputs.version_tag }} draft: true + body_path: CHANGELOG.md diff --git a/.github/workflows/release-production.yaml b/.github/workflows/release-production.yaml index 6067c4acf..f939f98e0 100644 --- a/.github/workflows/release-production.yaml +++ b/.github/workflows/release-production.yaml @@ -19,17 +19,17 @@ jobs: echo "VERSION_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT use-reusable-workflow: + strategy: + matrix: + directory: [api, client] name: Build Images needs: set_tags uses: ./.github/workflows/build-images.reusable.yaml with: - api_image_tags: | - iotaledger/explorer-api:${{ needs.set_tags.outputs.version_tag }} - iotaledger/explorer-api:latest - - client_image_tags: | - iotaledger/explorer-client:${{ needs.set_tags.outputs.version_tag }} - iotaledger/explorer-client:latest + directory: ${{ matrix.directory }} + image_tags: | + iotaledger/explorer-${{ matrix.directory }}:${{ needs.set_tags.outputs.version_tag }} + iotaledger/explorer-${{ matrix.directory }}:latest secrets: inherit deploy_to_server: diff --git a/.github/workflows/release-staging.yaml b/.github/workflows/release-staging.yaml index 033e2fa52..8556b8d54 100644 --- a/.github/workflows/release-staging.yaml +++ b/.github/workflows/release-staging.yaml @@ -33,14 +33,16 @@ jobs: fi use-reusable-workflow: - name: Build Images + strategy: + matrix: + directory: [api, client] + name: Build Image needs: set_tags uses: ./.github/workflows/build-images.reusable.yaml with: - api_image_tags: | - iotaledger/explorer-api:${{ needs.set_tags.outputs.version_tag }} - client_image_tags: | - iotaledger/explorer-client:${{ needs.set_tags.outputs.version_tag }} + directory: ${{ matrix.directory }} + image_tags: | + iotaledger/explorer-${{ matrix.directory }}:${{ needs.set_tags.outputs.version_tag }} secrets: inherit deploy_to_server: