-
-
Notifications
You must be signed in to change notification settings - Fork 62
Add automated CI workflow for releases #354
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,111 @@ | ||||||||||||||||
| name: Release on Version Change | ||||||||||||||||
|
|
||||||||||||||||
| on: | ||||||||||||||||
| push: | ||||||||||||||||
| branches: | ||||||||||||||||
| - master | ||||||||||||||||
| paths: | ||||||||||||||||
| - 'nixfmt.cabal' | ||||||||||||||||
|
|
||||||||||||||||
| jobs: | ||||||||||||||||
| release-if-version-changed: | ||||||||||||||||
| runs-on: ubuntu-latest | ||||||||||||||||
|
|
||||||||||||||||
| steps: | ||||||||||||||||
| - name: Checkout main | ||||||||||||||||
| uses: actions/checkout@v4 | ||||||||||||||||
| with: | ||||||||||||||||
| fetch-depth: 2 # need previous commit for comparison | ||||||||||||||||
|
|
||||||||||||||||
| - name: Get version from nixfmt.cabal | ||||||||||||||||
| id: get_version | ||||||||||||||||
| run: | | ||||||||||||||||
| CABAL_FILE="nixfmt.cabal" | ||||||||||||||||
|
|
||||||||||||||||
| # Extract the version | ||||||||||||||||
| VERSION=$(grep -m1 "^version:" $CABAL_FILE | awk '{print $2}') | ||||||||||||||||
| echo "Version found in cabal: $VERSION" | ||||||||||||||||
|
|
||||||||||||||||
| # Get previous version from last commit | ||||||||||||||||
| PREV_VERSION=$(git show HEAD~1:"$CABAL_FILE" | grep -m1 "^version:" | awk '{print $2}' || echo "none") | ||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm worried about us failing to parse the file and then strange things happening. Could we remove the
Suggested change
|
||||||||||||||||
| echo "Previous version: $PREV_VERSION" | ||||||||||||||||
|
|
||||||||||||||||
| # Export for later steps | ||||||||||||||||
| echo "version=$VERSION" >> $GITHUB_OUTPUT | ||||||||||||||||
| echo "prev_version=$PREV_VERSION" >> $GITHUB_OUTPUT | ||||||||||||||||
|
|
||||||||||||||||
| - name: Check if version changed | ||||||||||||||||
| id: compare | ||||||||||||||||
| run: | | ||||||||||||||||
| if [ "${{ steps.get_version.outputs.version }}" != "${{ steps.get_version.outputs.prev_version }}" ]; then | ||||||||||||||||
|
Comment on lines
+39
to
+40
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's important to pass inputs via env vars instead of directly interpolating into the shell script. Here's how:
Suggested change
Similar other interpolations below. |
||||||||||||||||
| echo "version_changed=true" >> $GITHUB_ENV | ||||||||||||||||
| echo "::notice ::✅ Version changed from ${{ steps.get_version.outputs.prev_version }} to ${{ steps.get_version.outputs.version }}" | ||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Indentation is a bit wonky here (and in the |
||||||||||||||||
| else | ||||||||||||||||
| echo "version_changed=false" >> $GITHUB_ENV | ||||||||||||||||
| echo "::notice ::Version did not change skipping release." | ||||||||||||||||
| fi | ||||||||||||||||
| - name: Extract changelog section for current version | ||||||||||||||||
| if: env.version_changed == 'true' | ||||||||||||||||
| run: | | ||||||||||||||||
| VERSION="${{ steps.get_version.outputs.version }}" | ||||||||||||||||
| echo "Extracting changelog section for version $VERSION" | ||||||||||||||||
|
|
||||||||||||||||
| # Extract everything after the "## <version>" header until the next "## " | ||||||||||||||||
| awk -v ver="$VERSION" ' | ||||||||||||||||
| $0 ~ "^##[[:space:]]+" ver {found=1; next} | ||||||||||||||||
| found && /^##[[:space:]]+/ {exit} | ||||||||||||||||
| found | ||||||||||||||||
| ' CHANGELOG.md > RELEASE_NOTES.md | ||||||||||||||||
|
|
||||||||||||||||
| if [ ! -s RELEASE_NOTES.md ]; then | ||||||||||||||||
| echo "::error ::⚠️ No changelog section found for version $VERSION" | ||||||||||||||||
| echo "(Make sure you have a header like '## $VERSION -- YYYY-MM-DD')" | ||||||||||||||||
| echo "- No notes will be attached to the release -" | ||||||||||||||||
| echo "No changelog section found for version $VERSION." > RELEASE_NOTES.md | ||||||||||||||||
| fi | ||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's explicitly exit nonzero:
Suggested change
|
||||||||||||||||
|
|
||||||||||||||||
| echo "---- Extracted Changelog ----" | ||||||||||||||||
| cat RELEASE_NOTES.md | ||||||||||||||||
| echo "--------------------------" | ||||||||||||||||
|
|
||||||||||||||||
| - name: Setup Nix | ||||||||||||||||
| if: env.version_changed == 'true' | ||||||||||||||||
| uses: cachix/install-nix-action@v26 | ||||||||||||||||
|
|
||||||||||||||||
| - name: Setup Cachix cache | ||||||||||||||||
| if: env.version_changed == 'true' | ||||||||||||||||
| uses: cachix/cachix-action@v14 | ||||||||||||||||
| with: | ||||||||||||||||
| name: nixos-nixfmt | ||||||||||||||||
| authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' | ||||||||||||||||
|
|
||||||||||||||||
| - name: Build static binary | ||||||||||||||||
| if: env.version_changed == 'true' | ||||||||||||||||
| run: | | ||||||||||||||||
| nix build -L .#nixfmt-static | ||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use stable nix here instead of flakes:
Suggested change
|
||||||||||||||||
| mkdir -p release | ||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we use this |
||||||||||||||||
| echo "artifact_path=result/bin/nixfmt" >> $GITHUB_ENV | ||||||||||||||||
|
|
||||||||||||||||
| - name: Create Git tag | ||||||||||||||||
| if: env.version_changed == 'true' | ||||||||||||||||
| run: | | ||||||||||||||||
| VERSION="${{ steps.get_version.outputs.version }}" | ||||||||||||||||
| TAG="v${VERSION}" | ||||||||||||||||
|
|
||||||||||||||||
| echo "Creating tag $TAG" | ||||||||||||||||
|
|
||||||||||||||||
| git config user.name "Github Actions" | ||||||||||||||||
| git config user.email "[email protected]" | ||||||||||||||||
| git tag -a "$TAG" -m "Release $TAG" | ||||||||||||||||
| git push origin "$TAG" | ||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use the |
||||||||||||||||
|
|
||||||||||||||||
| - name: Create GitHub Release | ||||||||||||||||
| if: env.version_changed == 'true' | ||||||||||||||||
| uses: softprops/action-gh-release@v2 | ||||||||||||||||
| with: | ||||||||||||||||
| tag_name: "v${{ steps.get_version.outputs.version }}" | ||||||||||||||||
| name: "v${{ steps.get_version.outputs.version }}" | ||||||||||||||||
| body_path: RELEASE_NOTES.md | ||||||||||||||||
| files: "${{ env.artifact_path }}" | ||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's just inline
Suggested change
|
||||||||||||||||
| env: | ||||||||||||||||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a default shell as done in https://github.com/NixOS/nixpkgs/blob/7a7849f5f075f6cfa8d6607c65048b7a22479bcb/.github/workflows/build.yml#L21-L23. A nice side effect of this is to get some sane shell behavior (
set -euo pipefailor something like that).