Final changes to release workflow to make submodule releases possible. (#1043)

* chmod +x for buildozer download.

* fix module name expansion

* fix path t module.bazl

* missing s

* no rpm test

* flips

* hack out the disk cache

* release_ruleset needs a revamp

* reroot

* commentary

* auto-create versoin from release

* update release tools to form download URL correctly
diff --git a/.github/workflows/release_module.yml b/.github/workflows/release_module.yml
index 3810176..5844796 100644
--- a/.github/workflows/release_module.yml
+++ b/.github/workflows/release_module.yml
@@ -38,7 +38,7 @@
         env:
           SUBDIR: "${{ inputs.subdir }}"
           VERSION: "${{ inputs.version }}"
-          MODULE: "rules_pkg_${SUBDIR}"
+          MODULE: "rules_pkg_${{ inputs.subdir }}"
 
           GIT_AUTHOR_NAME: "${{ github.actor }}"
           GIT_AUTHOR_EMAIL: "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com"
@@ -50,7 +50,9 @@
           curl -o "${RUNNER_TEMP}/buildozer" -L "https://github.com/bazelbuild/buildtools/releases/download/v7.3.1/buildozer-linux-amd64"
           chmod a+x "${RUNNER_TEMP}/buildozer"
           "${RUNNER_TEMP}/buildozer" "set version ${VERSION}" "//${SUBDIR}/MODULE.bazel:${MODULE}" || true
-          git add "${MODULE}/MODULE.bazel"
+          git add "${SUBDIR}/MODULE.bazel"
+          sed -i -e "s/@AUTO_VERSION@/${VERSION}/" ${SUBDIR}/version.bzl
+          git add "${SUBDIR}/version.bzl"
           git commit -m "Release `${MODULE}-${VERSION}`"
 
           # 3. Push release tag.
@@ -67,4 +69,10 @@
       # This will run release_prep.sh to do the dirty work.
       # TODO: https://github.com/bazelbuild/rules_pkg/issues/1031
       release_files: "bazel-bin/distro/rules_pkg_${{ inputs.subdir }}-*.tgz"
-      tag_name: "rule_pkg_${{ inputs.subdir }}-${{ inputs.version }}"
+      tag_name: "rules_pkg_${{ inputs.subdir }}-${{ inputs.version }}"
+      # We only do a partial test. The problem is that RPM does not work on the github runners
+      # so we must skip, but the release_ruleset flow appends cache flags to the command. That
+      # makes the syntax 'bazel test //... -- -//test/rpm/... =disk_cache-flag' impossible.
+      # It doesn't matter.  We have to do the full test anyway before hitting this, so everything
+      # should still work, if we only changed the version in the module.
+      bazel_test_command: "bazel test --build_tests_only //tests/tar/... //tests/zip/..."
diff --git a/.github/workflows/release_prep.sh b/.github/workflows/release_prep.sh
index 0aa194d..58777e9 100755
--- a/.github/workflows/release_prep.sh
+++ b/.github/workflows/release_prep.sh
@@ -5,8 +5,15 @@
 # Passed as argument when invoking the script.
 TAG="${1}"
 
-# Get back to the root
-cd ../../
+# Get back to the root, because sometimes we are in .github/workflows, but other times we are not.
+# That seems plainly dumb, but working around it is far less effort than writing new workflows
+# where this is not a problem.
+if [[ ! -f MODULE.bazel ]] ; then
+  cd ..
+fi
+if [[ ! -f MODULE.bazel ]] ; then
+  cd ..
+fi
 
 case "${TAG}" in
   [0-9]* )
diff --git a/distro/BUILD b/distro/BUILD
index dd431f4..aa0862f 100644
--- a/distro/BUILD
+++ b/distro/BUILD
@@ -150,6 +150,7 @@
     outs = ["rules_pkg_providers_relnotes.txt"],
     artifact_name = "rules_pkg_providers-%s.tgz" % providers_version,
     org = "bazelbuild",
-    repo = "rules_pkg_providers",
+    release_name = "rules_pkg_providers-%s" % providers_version,
+    repo = "rules_pkg",
     version = providers_version,
 )
diff --git a/pkg/releasing/defs.bzl b/pkg/releasing/defs.bzl
index 52f3cd4..bd90e55 100644
--- a/pkg/releasing/defs.bzl
+++ b/pkg/releasing/defs.bzl
@@ -5,16 +5,19 @@
         name,
         repo,
         version,
-        artifact_name = None,
         outs = None,
-        setup_file = "",
-        deps_method = "",
-        toolchains_method = "",
-        org = "bazelbuild",
+        artifact_name = None,
         changelog = None,
-        mirror_host = None):
+        deps_method = "",
+        mirror_host = None,
+        org = "bazelbuild",
+        release_name = None,
+        setup_file = "",
+        toolchains_method = ""):
     if not artifact_name:
         artifact_name = ":%s-%s.tar.gz" % (repo, version)
+    if not release_name:
+        release_name = ":%s-%s" % (repo, version)
 
     # Must use Label to get a path relative to the rules_pkg repository,
     # instead of the calling BUILD file.
@@ -26,6 +29,7 @@
         "--repo=%s" % repo,
         "--version=%s" % version,
         "--tarball=$(location %s)" % artifact_name,
+        "--release_name='%s'" % release_name,
     ]
     if setup_file:
         cmd.append("--setup_file=%s" % setup_file)
diff --git a/pkg/releasing/print_rel_notes.py b/pkg/releasing/print_rel_notes.py
index b9c4545..eb5d27b 100644
--- a/pkg/releasing/print_rel_notes.py
+++ b/pkg/releasing/print_rel_notes.py
@@ -24,13 +24,13 @@
 
 
 def print_notes(org, repo, version, tarball_path, mirror_host=None,
-                deps_method=None, setup_file=None, toolchains_method=None,
-                changelog=''):
+                deps_method=None, release_name=None, setup_file=None,
+		toolchains_method=None, changelog=''):
   file_name = os.path.basename(tarball_path)
   sha256 = release_tools.get_package_sha256(tarball_path)
 
   url = 'https://github.com/%s/%s/releases/download/%s/%s' % (
-      org, repo, version, file_name)
+      org, repo, release_name, file_name)
   mirror_url = 'https://%s/github.com/%s/%s/releases/download/%s/%s' % (
       mirror_host, org, repo, version, file_name) if mirror_host else None
   workspace_stanza = release_tools.workspace_content(
@@ -70,10 +70,10 @@
   }))
   if mirror_url:
     file = os.path.basename(tarball_path)
-    path = 'github.com/{org}/{repo}/releases/download/{version}/{file}'.format(
+    path = 'github.com/{org}/{repo}/releases/download/{release_name}/{file}'.format(
         org=org,
         repo=repo,
-        version=version,
+        release_name=release_name,
         file=file
     )
 
@@ -110,6 +110,8 @@
   parser.add_argument(
       '--version', default=None, required=True, help='Release version')
   parser.add_argument(
+      '--release_name', default=None, required=True, help='The release name: usually submodule-version')
+  parser.add_argument(
       '--tarball_path', default=None,
       required=True, help='path to release tarball')
   parser.add_argument(
@@ -139,6 +141,7 @@
               deps_method=options.deps_method,
               changelog=changelog,
               mirror_host=options.mirror_host,
+	      release_name=options.release_name,
               setup_file=options.setup_file,
               toolchains_method=options.toolchains_method)
 
diff --git a/providers/version.bzl b/providers/version.bzl
index ead02a6..f05dc98 100644
--- a/providers/version.bzl
+++ b/providers/version.bzl
@@ -1,3 +1,3 @@
 """The version of rules_pkg_providers."""
 
-version = "1.0.0"
+version = "@AUTO_VERSION@"