Skip to content

Commit 379f9d8

Browse files
committed
Use gh command to create and add to release
This makes substantial changes to the release workflow, most of them straightforwardly adapted from corresponding material in the ripgrep release workflow: - 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, the uses of shell expansion rather than `${{ }}` interpolation for the environment variables, and the omission of checksum files since we are not currently generating those. This notably does not add either of the following to the workflow: - This does not set `permissions:` for the workflow. It was not set before, so the configuration, including in the upstream repo, seems not to require it. (Note that this does not imply that the configuration in the ripgrep repo doesn't require it.) - This does try to do anything explicit to take the place of specifying `omitBody: true` for ncipollo/release-action. I'm not sure what should be done for this, but the current behavior seems to produce the same result, and passing `--notes ''` to `gh` might go too far. The current ripgrep workflow has no explicit argument corresponding to this.
1 parent b67c0fd commit 379f9d8

File tree

1 file changed

+31
-60
lines changed

1 file changed

+31
-60
lines changed

.github/workflows/release.yml

Lines changed: 31 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# This is largely adapted from past and recent versions of the ripgrep release workflow.
1+
# This is largely adapted from the ripgrep release workflow.
22
# https://github.com/BurntSushi/ripgrep/blob/master/.github/workflows/release.yml
33

44
name: release
@@ -65,33 +65,12 @@ jobs:
6565
esac
6666
6767
- name: Create GitHub release
68-
id: release
69-
uses: ncipollo/release-action@v1
70-
with:
71-
tag: ${{ env.VERSION }}
72-
name: ${{ env.VERSION }}
73-
allowUpdates: true
74-
draft: true
75-
omitBody: true
76-
omitPrereleaseDuringUpdate: true
77-
token: ${{ secrets.GITHUB_TOKEN }}
78-
79-
- name: Create artifacts directory
80-
run: mkdir artifacts
81-
82-
- name: Save release upload URL to artifact
83-
run: echo "$URL" > artifacts/release-upload-url
68+
run: gh release create "$VERSION" --title="$VERSION" --draft
8469
env:
85-
URL: ${{ steps.release.outputs.upload_url }}
70+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8671

87-
- name: Save version number to artifact
88-
run: echo "$VERSION" > artifacts/release-version
89-
90-
- name: Upload artifacts
91-
uses: actions/upload-artifact@v4
92-
with:
93-
name: artifacts
94-
path: artifacts
72+
outputs:
73+
version: ${{ env.VERSION }}
9574

9675
build-release:
9776
name: build-release
@@ -199,17 +178,6 @@ jobs:
199178
echo "target flag is: $TARGET_FLAGS"
200179
echo "target dir is: $TARGET_DIR"
201180
202-
- name: Get release download URL
203-
uses: actions/download-artifact@v4
204-
with:
205-
name: artifacts
206-
path: artifacts
207-
208-
- name: Set release upload URL and release version
209-
run: |
210-
echo "UPLOAD_URL=$(< artifacts/release-upload-url)" >> "$GITHUB_ENV"
211-
echo "VERSION=$(< artifacts/release-version)" >> "$GITHUB_ENV"
212-
213181
- name: Build release binary
214182
run: |
215183
"$CARGO" build --verbose --release "$TARGET_FLAGS" --no-default-features --features "$FEATURE"
@@ -228,33 +196,36 @@ jobs:
228196
/target/arm-unknown-linux-gnueabihf/release/ein \
229197
/target/arm-unknown-linux-gnueabihf/release/gix
230198
231-
- name: Build archive
199+
- name: Determine version
200+
run: echo "VERSION=$VERSION" >> "$GITHUB_ENV"
201+
env:
202+
VERSION: ${{ needs.create-release.outputs.version }}
203+
204+
- name: Determine archive basename
205+
run: echo "ARCHIVE=gitoxide-$FEATURE-$VERSION-$TARGET" >> "$GITHUB_ENV"
206+
207+
- name: Pre-populate directory for archive
232208
run: |
233-
staging="gitoxide-$FEATURE-$VERSION-$TARGET"
234-
mkdir -p -- "$staging"
209+
mkdir -- "$ARCHIVE"
210+
cp {README.md,LICENSE-*,CHANGELOG.md} "$ARCHIVE/"
235211
236-
cp {README.md,LICENSE-*,CHANGELOG.md} "$staging/"
212+
- name: Build archive (Windows)
213+
if: matrix.os == 'windows-latest'
214+
run: |
215+
file -- "$TARGET_DIR"/release/{ein,gix}.exe
216+
cp -- "$TARGET_DIR"/release/{ein,gix}.exe "$ARCHIVE/"
217+
7z a "$ARCHIVE.zip" "$ARCHIVE"
218+
echo "ASSET=$ARCHIVE.zip" >> "$GITHUB_ENV"
237219
238-
if [ "$OS" = 'windows-latest' ]; then
239-
file -- "$TARGET_DIR"/release/{ein,gix}.exe
240-
cp -- "$TARGET_DIR"/release/{ein,gix}.exe "$staging/"
241-
7z a "$staging.zip" "$staging"
242-
echo "ASSET=$staging.zip" >> "$GITHUB_ENV"
243-
else
244-
file -- "$TARGET_DIR"/release/{ein,gix}
245-
cp -- "$TARGET_DIR"/release/{ein,gix} "$staging/"
246-
tar czf "$staging.tar.gz" "$staging"
247-
echo "ASSET=$staging.tar.gz" >> "$GITHUB_ENV"
248-
fi
249-
env:
250-
OS: ${{ matrix.os }}
220+
- name: Build archive (Unix)
221+
if: matrix.os != 'windows-latest'
222+
run: |
223+
file -- "$TARGET_DIR"/release/{ein,gix}
224+
cp -- "$TARGET_DIR"/release/{ein,gix} "$ARCHIVE/"
225+
tar czf "$ARCHIVE.tar.gz" "$ARCHIVE"
226+
echo "ASSET=$ARCHIVE.tar.gz" >> "$GITHUB_ENV"
251227
252228
- name: Upload release archive
253-
uses: actions/upload-release-asset@v1.0.2
229+
run: gh release upload "$VERSION" "$ASSET"
254230
env:
255231
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
256-
with:
257-
upload_url: ${{ env.UPLOAD_URL }}
258-
asset_path: ${{ env.ASSET }}
259-
asset_name: ${{ env.ASSET }}
260-
asset_content_type: application/octet-stream

0 commit comments

Comments
 (0)