From 1b54b352142c41b0b3b4fafee9aa9242523d9783 Mon Sep 17 00:00:00 2001 From: Rafid Bin Mostofa Date: Tue, 11 Jul 2023 12:21:56 +0600 Subject: [PATCH] chore(release): add automated release workflow (#2) * chore(release): add automated release workflow Adds a workflow file which can be run to create a semantic tag and immediately afterwards, create a release on GitHub. Any collaborator with write access should be able to trigger the workflow. This commit also adds another workflow file, which leaves a comment after a PR has been merged. The comment reminds to trigger the aforementioned release workflow. * chore: delete pr commenter * chore: fix naming and specify defaults * chore: skip release if release exists * chore: release if tag is provided to the step properly * chore: default bump is patch if no input tag * chore: attach files to GitHub release Per feedback: https://github.com/canonical/rocks-toolbox/pull/2#discussion_r1255686934 * chore: remove . directory from the archive * chore: make sure to pass down the archive file name --- .github/workflows/release.yml | 52 +++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..31026b8 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,52 @@ +name: Tag and Release + +on: + workflow_dispatch: + inputs: + tag: + description: "Tag (Optional, without 'v' e.g. 1.2.3)" + required: false + +jobs: + release: + name: Tag and release + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v2 + + - name: Bump version and push tag + id: tag_version + uses: mathieudutour/github-tag-action@v6.1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + default_bump: ${{ inputs.tag == '' && 'patch' || false }} + custom_tag: ${{ inputs.tag }} + + - name: Prepare archive + id: prep_archive + env: + TAG: ${{ steps.tag_version.outputs.new_tag }} + run: | + ARCHIVE_FILE=rocks-toolbox_${TAG}.tar.gz + echo "Creating archive $ARCHIVE_FILE" + + dir=dist/${TAG} + mkdir -p $dir + cp chisel-wrapper $dir + cp LICENSE README.md $dir + find $dir -printf "%P\n" | tar -czf dist/$ARCHIVE_FILE --no-recursion -C $dir -T - + + echo "ARCHIVE_FILE=${ARCHIVE_FILE}" >>$GITHUB_OUTPUT + + - name: Create GitHub release + uses: ncipollo/release-action@v1.12.0 + if: startsWith(${{ steps.tag_version.outputs.new_tag }}, 'v') + with: + name: ${{ steps.tag_version.outputs.new_tag }} + tag: ${{ steps.tag_version.outputs.new_tag }} + body: ${{ steps.tag_version.outputs.changelog }} + generateReleaseNotes: true + skipIfReleaseExists: true + artifacts: dist/${{ steps.prep_archive.outputs.ARCHIVE_FILE }}