name: Continuous Deployment on: push: tags: - "v*.*.*" jobs: generate-changelog: name: Generate changelog runs-on: ubuntu-18.04 outputs: release_body: ${{ steps.release.outputs.release_body }} steps: - name: Checkout uses: actions/checkout@main with: fetch-depth: 0 - name: Generate a changelog uses: orhun/git-cliff-action@v1 id: git-cliff with: config: config/cliff.toml args: -vv --latest --strip header env: OUTPUT: CHANGES.md - name: Set the release body id: release shell: bash run: | r=$(cat ${{ steps.git-cliff.outputs.changelog }}) r="$(printf "$r" | tail -n +3)" r="${r//'%'/'%25'}" r="${r//$'\n'/'%0A'}" r="${r//$'\r'/'%0D'}" echo "::set-output name=release_body::$r" publish-github: name: Publish on GitHub needs: generate-changelog runs-on: ${{ matrix.os }} strategy: matrix: build: [linux-gnu, linux-musl, win-gnu, win-msvc, win32-msvc, macos] include: - BUILD: linux-gnu OS: ubuntu-18.04 TOOLCHAIN: stable TARGET: x86_64-unknown-linux-gnu - BUILD: linux-musl OS: ubuntu-18.04 TOOLCHAIN: stable TARGET: x86_64-unknown-linux-musl - BUILD: win-gnu OS: windows-2019 TOOLCHAIN: stable TARGET: x86_64-pc-windows-gnu - BUILD: win-msvc OS: windows-2019 TOOLCHAIN: stable TARGET: x86_64-pc-windows-msvc - BUILD: win32-msvc OS: windows-2019 TOOLCHAIN: stable TARGET: i686-pc-windows-msvc - BUILD: macos OS: macos-10.15 TOOLCHAIN: stable TARGET: x86_64-apple-darwin steps: - name: Checkout uses: actions/checkout@main - name: Set the release version shell: bash run: echo "RELEASE_VERSION=${GITHUB_REF:11}" >> $GITHUB_ENV - name: Install musl-tools if: matrix.TARGET == 'x86_64-unknown-linux-musl' run: | sudo apt-get update sudo apt-get install -y --no-install-recommends \ --allow-unauthenticated musl-tools - name: Install Rust toolchain uses: actions-rs/toolchain@v1 with: toolchain: ${{ matrix.TOOLCHAIN }} target: ${{ matrix.TARGET }} override: true - name: Build run: cargo build --release --locked --target ${{ matrix.TARGET }} - name: Prepare release assets shell: bash run: | mkdir -p release/completions/ cp {LICENSE,README.md,CHANGELOG.md} release/ OUT_DIR=release/completions/ cargo run --release --bin git-cliff-completions if [ "${{ matrix.OS }}" = "windows-2019" ]; then cp target/${{ matrix.TARGET }}/release/git-cliff.exe release/ else cp target/${{ matrix.TARGET }}/release/git-cliff release/ fi mv release/ git-cliff-${{ env.RELEASE_VERSION }}/ - name: Create release artifacts shell: bash run: | if [ "${{ matrix.OS }}" = "windows-2019" ]; then 7z a -tzip "git-cliff-${{ env.RELEASE_VERSION }}-${{ matrix.TARGET }}.zip" \ git-cliff-${{ env.RELEASE_VERSION }}/ else tar -czvf git-cliff-${{ env.RELEASE_VERSION }}-${{ matrix.TARGET }}.tar.gz \ git-cliff-${{ env.RELEASE_VERSION }}/ shasum -a 512 git-cliff-${{ env.RELEASE_VERSION }}-${{ matrix.TARGET }}.tar.gz \ > git-cliff-${{ env.RELEASE_VERSION }}-${{ matrix.TARGET }}.tar.gz.sha512 fi - name: Sign the release if: matrix.OS == 'ubuntu-18.04' || matrix.OS == 'macos-10.15' run: | echo "${{ secrets.GPG_RELEASE_KEY }}" | base64 --decode > private.key echo "${{ secrets.GPG_PASSPHRASE }}" | gpg --pinentry-mode=loopback \ --passphrase-fd 0 --import private.key echo "${{ secrets.GPG_PASSPHRASE }}" | gpg --pinentry-mode=loopback \ --passphrase-fd 0 --detach-sign \ git-cliff-${{ env.RELEASE_VERSION }}-${{ matrix.TARGET }}.tar.gz - name: Upload the release uses: svenstaro/upload-release-action@v2 with: repo_token: ${{ secrets.GITHUB_TOKEN }} file: git-cliff-${{ env.RELEASE_VERSION }}-${{ matrix.TARGET }}* file_glob: true overwrite: true tag: ${{ github.ref }} release_name: "Release v${{ env.RELEASE_VERSION }}" body: "${{ needs.generate-changelog.outputs.release_body }}" publish-docker: name: Publish the Docker image needs: publish-github runs-on: ubuntu-18.04 steps: - name: Checkout uses: actions/checkout@main - name: Set the release version run: echo "RELEASE_VERSION=${GITHUB_REF:11}" >> $GITHUB_ENV - name: Build run: docker build -t git-cliff . - name: Tag run: | docker tag git-cliff orhunp/git-cliff:${{ env.RELEASE_VERSION }} docker tag git-cliff docker.pkg.github.com/orhun/git-cliff/git-cliff:${{ env.RELEASE_VERSION }} - name: Login (Docker Hub) run: echo ${{ secrets.DOCKERHUB_PASS }} | docker login -u orhunp --password-stdin - name: Push (Docker Hub) run: docker push orhunp/git-cliff:${{ env.RELEASE_VERSION }} - name: Login (Package Registry) run: echo ${{ secrets.GITHUB_TOKEN }} | docker login -u orhun docker.pkg.github.com --password-stdin - name: Push (Package Registry) run: docker push docker.pkg.github.com/orhun/git-cliff/git-cliff:${{ env.RELEASE_VERSION }} publish-crates-io: name: Publish on crates.io needs: publish-github runs-on: ubuntu-18.04 steps: - name: Checkout uses: actions/checkout@main - name: Set the release version run: echo "RELEASE_VERSION=${GITHUB_REF:11}" >> $GITHUB_ENV - name: Prepare the files to embed run: | mkdir -p target/package/config/ cp config/cliff.toml target/package/config/ - name: Publish the library uses: actions-rs/cargo@v1 with: command: publish args: | --manifest-path git-cliff-core/Cargo.toml --locked --token ${{ secrets.CARGO_TOKEN }} - name: Wait for library to update shell: bash run: | crate_status="https://raw.githubusercontent.com/rust-lang/crates.io-index/master/gi/t-/git-cliff-core" until curl -s "$crate_status" | grep -q '"vers":"${{ env.RELEASE_VERSION }}"'; do sleep 5; done; - name: Fetch the dependencies uses: actions-rs/cargo@v1 with: command: fetch args: --manifest-path git-cliff/Cargo.toml - name: Prepare the files to embed shell: bash run: | for d in /home/runner/.cargo/registry/src/github.com-*/ ; do mkdir "$d"/config/ cp config/cliff.toml "$d"/config/ done - name: Publish the binary uses: actions-rs/cargo@v1 with: command: publish args: | --manifest-path git-cliff/Cargo.toml --locked --token ${{ secrets.CARGO_TOKEN }}