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 new file mode 100644 index 000000000..40dc71615 --- /dev/null +++ b/.github/workflows/create-draft-release.reusable.yaml @@ -0,0 +1,75 @@ +name: Create Draft Release + +on: + workflow_call: + inputs: + name: + required: true + type: string + version_tag: + required: true + type: string + +jobs: + github_draft_release: + name: Create Draft Release + runs-on: ubuntu-latest + steps: + - 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 46692a880..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: @@ -48,3 +48,11 @@ jobs: - name: Deploy to Server run: | ssh -o StrictHostKeyChecking=no updater@${{ secrets.EXPLORER_GATEWAY }} "${{ matrix.environment }} ${{ needs.set_tags.outputs.version_tag }}" + + create_draft_release: + name: Create Draft Release + needs: [set_tags, use-reusable-workflow, deploy_to_server] + uses: ./.github/workflows/create-draft-release.reusable.yaml + with: + name: Explorer ${{ needs.set_tags.outputs.version_tag }} + version_tag: ${{ needs.set_tags.outputs.version_tag }} diff --git a/.github/workflows/release-staging.yaml b/.github/workflows/release-staging.yaml index 2301bac56..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: @@ -59,3 +61,11 @@ jobs: - name: Deploy to Server run: | ssh -o StrictHostKeyChecking=no updater@${{ secrets.EXPLORER_GATEWAY }} "${{ matrix.environment }} ${{ needs.set_tags.outputs.version_tag }}" + + create_draft_release: + name: Create Draft Release + needs: [set_tags, use-reusable-workflow, deploy_to_server] + uses: ./.github/workflows/create-draft-release.reusable.yaml + with: + name: Explorer ${{ needs.set_tags.outputs.version_tag }} + version_tag: ${{ needs.set_tags.outputs.version_tag }}