Skip to content

Commit

Permalink
Use gh command to create and add to release
Browse files Browse the repository at this point in the history
This makes substantial changes to the release workflow, most of
them lightly adapted from corresponding material in the ripgrep
release workflow. The biggest changes, all adapted directly from
ripgrep, are:

- The biggest change is to use `gh` (the GitHub CLI) instead of
  both the ncipollo/release-action and actions/upload-release-asset
  actions.

- Use outputs instead of artifacts for the information that needs
  to go from the `create-release` job into the `build-release`
  jobs. This eliminates the need for actions/upload-artifact and
  actions/download-artifact.

  Furthermore, since `gh` doesn't require a URL to add files to an
  existing release, there is only one output, the version.

- Split up the "Build archive" step so it doesn't need awkward
  conditional logic inside a single script step. Now the platform
  agnostic part of creating the directory and putting documentation
  in it is one step, followed by steps with `if:` keys for Windows
  and Unix.

  For this, the main differences from how it is currently written
  in the ripgrep workflow are the step titles and the uses of
  shell expansion rather than `${{ }}` interpolation for the
  environment variables.

Unlike in the corresponding material in ripgrep, this does not
compute and upload checksum files.

I believe this change is not quite complete, and may not work yet:

- I haven't added an explicit `permissions:` in case it might not
  be needed, but I expect I might need to add it.

- When ncipollo/release-action was used, `omitBody: true` was
  specified. I'm not sure if I need to do anything for that, like
  passing `--notes ''` to `gh`. But I'm not sure that would really
  be equivalent, and it might be wrong. For now, I am leaving it
  out.
  • Loading branch information
EliahKagan committed Aug 1, 2024
1 parent 7156657 commit 5018e62
Showing 1 changed file with 31 additions and 60 deletions.
91 changes: 31 additions & 60 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This is largely adapted from past and recent versions of the ripgrep release workflow.
# This is largely adapted from the ripgrep release workflow.
# https://github.com/BurntSushi/ripgrep/blob/master/.github/workflows/release.yml

name: release
Expand Down Expand Up @@ -65,33 +65,12 @@ jobs:
esac
- name: Create GitHub release
id: release
uses: ncipollo/release-action@v1
with:
tag: ${{ env.VERSION }}
name: ${{ env.VERSION }}
allowUpdates: true
draft: true
omitBody: true
omitPrereleaseDuringUpdate: true
token: ${{ secrets.GITHUB_TOKEN }}

- name: Create artifacts directory
run: mkdir artifacts

- name: Save release upload URL to artifact
run: echo "$URL" > artifacts/release-upload-url
run: gh release create "$VERSION" --title="$VERSION" --draft
env:
URL: ${{ steps.release.outputs.upload_url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Save version number to artifact
run: echo "$VERSION" > artifacts/release-version

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: artifacts
path: artifacts
outputs:
version: ${{ env.VERSION }}

build-release:
name: build-release
Expand Down Expand Up @@ -199,17 +178,6 @@ jobs:
echo "target flag is: $TARGET_FLAGS"
echo "target dir is: $TARGET_DIR"
- name: Get release download URL
uses: actions/download-artifact@v4
with:
name: artifacts
path: artifacts

- name: Set release upload URL and release version
run: |
echo "UPLOAD_URL=$(< artifacts/release-upload-url)" >> "$GITHUB_ENV"
echo "VERSION=$(< artifacts/release-version)" >> "$GITHUB_ENV"
- name: Build release binary
run: |
"$CARGO" build --verbose --release "$TARGET_FLAGS" --no-default-features --features "$FEATURE"
Expand All @@ -228,33 +196,36 @@ jobs:
/target/arm-unknown-linux-gnueabihf/release/ein \
/target/arm-unknown-linux-gnueabihf/release/gix
- name: Build archive
- name: Determine version
run: echo "VERSION=$VERSION" >> "$GITHUB_ENV"
env:
VERSION: ${{ needs.create-release.outputs.version }}

- name: Determine archive basename
run: echo "ARCHIVE=gitoxide-$FEATURE-$VERSION-$TARGET" >> "$GITHUB_ENV"

- name: Pre-populate directory for archive
run: |
staging="gitoxide-$FEATURE-$VERSION-$TARGET"
mkdir -p -- "$staging"
mkdir -- "$ARCHIVE"
cp {README.md,LICENSE-*,CHANGELOG.md} "$ARCHIVE/"
cp {README.md,LICENSE-*,CHANGELOG.md} "$staging/"
- name: Build archive (Windows)
if: matrix.os == 'windows-latest'
run: |
file -- "$TARGET_DIR"/release/{ein,gix}.exe
cp -- "$TARGET_DIR"/release/{ein,gix}.exe "$ARCHIVE/"
7z a "$ARCHIVE.zip" "$ARCHIVE"
echo "ASSET=$ARCHIVE.zip" >> "$GITHUB_ENV"
if [ "$OS" = 'windows-latest' ]; then
file -- "$TARGET_DIR"/release/{ein,gix}.exe
cp -- "$TARGET_DIR"/release/{ein,gix}.exe "$staging/"
7z a "$staging.zip" "$staging"
echo "ASSET=$staging.zip" >> "$GITHUB_ENV"
else
file -- "$TARGET_DIR"/release/{ein,gix}
cp -- "$TARGET_DIR"/release/{ein,gix} "$staging/"
tar czf "$staging.tar.gz" "$staging"
echo "ASSET=$staging.tar.gz" >> "$GITHUB_ENV"
fi
env:
OS: ${{ matrix.os }}
- name: Build archive (Unix)
if: matrix.os != 'windows-latest'
run: |
file -- "$TARGET_DIR"/release/{ein,gix}
cp -- "$TARGET_DIR"/release/{ein,gix} "$ARCHIVE/"
tar czf "$ARCHIVE.tar.gz" "$ARCHIVE"
echo "ASSET=$ARCHIVE.tar.gz" >> "$GITHUB_ENV"
- name: Upload release archive
uses: actions/upload-release[email protected]
run: gh release upload "$VERSION" "$ASSET"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ env.UPLOAD_URL }}
asset_path: ${{ env.ASSET }}
asset_name: ${{ env.ASSET }}
asset_content_type: application/octet-stream

0 comments on commit 5018e62

Please sign in to comment.