Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rules_docker release github workflow #2106

Merged
merged 12 commits into from
Jun 21, 2022
47 changes: 47 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# This GitHub workflow is triggered when a new tag is pushed.
# A release is then created from this tag.

name: Release

on:
push:
tags:
- "v*.*.*"

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Get pushed tag
id: get_tag
run: echo ::set-output name=TAG::${GITHUB_REF/refs\/tags\//}

- name: Download repository archive at pushed tag
run: "curl -L https://github.com/${{ github.repository_owner }}/${{ github.event.repository.name }}/archive/refs/tags/${{ steps.get_tag.outputs.TAG }}.tar.gz -o rules_docker-${{ steps.get_tag.outputs.TAG }}.tar.gz"

- name: Get SHA256 of archive
id: get_sha
run: echo "::set-output name=sha::$(sha256sum rules_docker-${{ steps.get_tag.outputs.TAG }}.tar.gz | cut -f 1 -d ' ')"

- name: Get version
id: get_version
run: |
VERSION=${{ steps.get_tag.outputs.TAG }}
echo "VERSION=${VERSION:1}" >> $GITHUB_ENV

- name: Create Release
uses: softprops/action-gh-release@v1
with:
body: |
Copy the following into your WORKSPACE file to use rules_docker at release ${{ steps.get_tag.outputs.TAG }}
```
http_archive(
name = "io_bazel_rules_docker",
sha256 = "${{ steps.get_sha.outputs.sha }}",
strip_prefix = "rules_docker-${{ env.VERSION }}",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we may be able to remove the need for the strip_prefix?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @uhthomas, I actually think I prefer to leave it in so we don't need to extract/recpompress things as that feels a little unnatural. However, if we want to remove it at a later stage we would just need to:

  1. After https://github.com/bazelbuild/rules_docker/pull/2106/files#diff-87db21a973eed4fef5f32b267aa60fcee5cbdf03c67fafdc2a9b553bb0b15f34R21 is downloaded, extract the contents.
  2. Move into the top level directory & compress the contents of that instead of the parent directory.
  3. Use this new tar.gz instead of the other one for generating SHA, uploading etc.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.

We could use git archive?

- uses: actions/checkout@v3
- run: git archive --output=rules_docker-${{ steps.get_tag.outputs.TAG }}.tar.gz ${{ steps.get_tag.outputs.TAG }}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even better, we could make tar.zst archives. Smaller and faster to compress/decompress. Though this would require Bazel 5.2.0. Maybe both? I guess we can do this in a follow up PR. Just wanted to write this down somewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah doing that in a follow up makes sense. I can probably look at it, but won't get a chance this week. Could be good to try what we have here so far with the next release anyway.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you happy to try the git archive thing? It would be really nice to remove the requirement for strip_prefix as most other rulesets don't for major releases. If you don't have time, I'm happy to add a commit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can probably get to this next week but if you'd like to try it in the meantime, feel free to add a commit. Otherwise, I'll try next week.

Copy link
Contributor Author

@kriscfoster kriscfoster Jun 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@uhthomas actually had some time this evening & pushed the change so strip_prefix isn't needed. Your suggestion worked. Basically, the extracted parent dir just needs to match the name of the tar & then strip_prefix isn't needed so git archive works a treat. Thank you!

urls = ["https://github.com/bazelbuild/rules_docker/releases/download/${{ steps.get_tag.outputs.TAG }}/rules_docker-${{ steps.get_tag.outputs.TAG }}.tar.gz"],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
urls = ["https://github.com/bazelbuild/rules_docker/releases/download/${{ steps.get_tag.outputs.TAG }}/rules_docker-${{ steps.get_tag.outputs.TAG }}.tar.gz"],
urls = ["https://github.com/${{ github.repository_owner }}/${{ github.event.repository.name }}/releases/download/${{ steps.get_tag.outputs.TAG }}/rules_docker-${{ steps.get_tag.outputs.TAG }}.tar.gz"],

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, updated to be more dynamic. The generated release information works automatically for forks now as-well.

)
```
generate_release_notes: true
files: rules_docker-${{ steps.get_tag.outputs.TAG }}.tar.gz