Skip to content

Commit

Permalink
update,ci,readme: put templated body into release instead of readme (#37
Browse files Browse the repository at this point in the history
)
  • Loading branch information
lilyinstarlight authored Aug 13, 2022
1 parent 4ca297f commit 2f45dbf
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 141 deletions.
14 changes: 7 additions & 7 deletions .ci/create-prerelease.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
module.exports = async ({require, context, core, github}) => {
if (!process.env.HYDRA_EVAL || !process.env.NIX_RELEASE)
throw new Error('HYDRA_EVAL or NIX_RELEASE empty or undefined');
if (!process.env.NIX_RELEASE)
throw new Error('NIX_RELEASE empty or undefined');

const fs = require('fs');
const os = require('os');
const path = require('path');

const hydra_eval = process.env.HYDRA_EVAL;
const nix_release = process.env.NIX_RELEASE;

const dist_dir = './dist';
const body_name = 'RELEASE.md';

const tag = nix_release;
const name = `${nix_release}`;
const body = `https://hydra.nixos.org/eval/${hydra_eval}`;

const asset_dir = './dist';
const body = fs.readFileSync(path.join(dist_dir, body_name), 'utf8');

const assets = Object.fromEntries(fs.readdirSync(asset_dir).map((file_name) => [file_name, path.join(asset_dir, file_name)]));
const assets = Object.fromEntries(fs.readdirSync(dist_dir).filter((file_name) => file_name != body_name).map((file_name) => [file_name, path.join(dist_dir, file_name)]));

core.startGroup('Release information');

Expand Down
24 changes: 2 additions & 22 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ jobs:
name: Update
runs-on: ubuntu-latest
outputs:
hydra_eval: ${{ steps.update.outputs.hydra_eval }}
nix_release: ${{ steps.update.outputs.nix_release }}
updated: ${{ steps.update.outputs.updated }}
steps:
Expand All @@ -31,24 +30,20 @@ jobs:
id: update
run: ./update.rb

- name: Push changes
- name: Push release tag
if: steps.update.outputs.updated == 'true'
env:
NIX_RELEASE: ${{ steps.update.outputs.nix_release }}
run: |
[ -n "$NIX_RELEASE" ] || (echo 'NIX_RELEASE empty or undefined' >&2; exit 1)
git commit -m "Release $NIX_RELEASE" README.md
git push origin HEAD:update/"$NIX_RELEASE"
git tag "$NIX_RELEASE"
git push origin "$NIX_RELEASE"
- name: Create release
if: steps.update.outputs.updated == 'true'
uses: actions/github-script@v6
env:
HYDRA_EVAL: ${{ steps.update.outputs.hydra_eval }}
NIX_RELEASE: ${{ steps.update.outputs.nix_release }}
with:
script: await require('.ci/create-prerelease.js')({require, context, core, github});
Expand Down Expand Up @@ -106,22 +101,7 @@ jobs:
git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
- name: Update main branch
env:
NIX_RELEASE: ${{ needs.update.outputs.nix_release }}
run: |
[ -n "$NIX_RELEASE" ] || (echo 'NIX_RELEASE empty or undefined' >&2; exit 1)
git pull origin "$GITHUB_REF"
git cherry-pick origin/update/"$NIX_RELEASE"
git push origin "$GITHUB_REF"
git tag -f "$NIX_RELEASE"
git push -f origin "$NIX_RELEASE"
git push origin -d update/"$NIX_RELEASE"
- name: Create full release
- name: Mark full release
uses: actions/github-script@v6
env:
NIX_RELEASE: ${{ needs.update.outputs.nix_release }}
Expand Down
51 changes: 3 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,12 @@
# Nix unstable installer
# Nix Unstable Installer

This project is about making Nix unstable release available to the general
This project is about making Nix unstable releases available to the general
public. It allows to test and use preview features like Flakes and provide
early feedback.

All it does is copy the release tarballs from Hydra and tweak the install
script so that it fetches them from GitHub instead.

## Latest release

* Release: `nix-2.10.0pre20220808_73fde9e`
* Hydra eval: <https://hydra.nixos.org/eval/1775204>

## Usage

### Systems

```sh
sh <(curl -L https://github.com/numtide/nix-unstable-installer/releases/download/nix-2.10.0pre20220808_73fde9e/install)
```

### GitHub Actions

Here is an example using Flakes:

```yaml
name: "Test"
on:
pull_request:
push:
jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v17
with:
install_url: https://github.com/numtide/nix-unstable-installer/releases/download/nix-2.10.0pre20220808_73fde9e/install
# Run the general flake checks
- run: nix flake check
# Verify that the main program builds
- run: nix shell -c echo OK
```
### Docker
```sh
docker run --rm -ti ghcr.io/numtide/nix-unstable-installer/nix:2.10.0pre20220808_73fde9e
```

## Current release process

* Run `./update.rb [eval_id]` (uses latest successful if no eval ID given)
* Commit and tag with the release name
* Push to GitHub
* Create a new GitHub release and attach all files in the ./dist folder
Pick the release that you want to use. Each release has a usage instruction attached to it: <https://github.com/numtide/nix-unstable-installer/releases/latest>
57 changes: 0 additions & 57 deletions README.md.erb

This file was deleted.

47 changes: 47 additions & 0 deletions RELEASE.md.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
## Release Information

* Release name: `<%= release_name %>`
* Hydra eval: <https://hydra.nixos.org/eval/<%= eval_id %>>

## Usage

### Linux + macOS Systems

```sh
sh <(curl -L <%= server_url %>/<%= repository %>/releases/download/<%= release_name %>/install)
```

### GitHub Actions

Example using Flakes:

```yaml
name: "Example Flake Workflow"

on:
pull_request:
push:

jobs:
tests:
name: Run tests
runs-on: ubuntu-latest
steps:
- uses: cachix/install-nix-action@<%= install_nix_action_version %>
with:
install_url: <%= server_url %>/<%= repository %>/releases/download/<%= release_name %>/install

- uses: actions/checkout@v3

# Run the general flake checks
- run: nix flake check

# Verify that the main program builds
- run: nix shell -c echo OK
```

### Docker / Podman

```sh
docker run --rm -ti ghcr.io/<%= repository %>/nix:<%= release_name.delete_prefix("nix-") %>
```
13 changes: 6 additions & 7 deletions update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ def download(url, path)
system("curl", "-sfL", "-o", path, url)
end

def render_readme(eval_id, release_name, server_url, repository, install_nix_action_version)
def render_release(eval_id, release_name, server_url, repository, install_nix_action_version)
b = binding
ERB.new(File.read("README.md.erb")).result b
ERB.new(File.read("RELEASE.md.erb")).result b
end

def rewrite(path, &block)
Expand Down Expand Up @@ -142,16 +142,16 @@ def get_eval(eval_id, skip_existing_tag = false)
)
end

# Get cachix/install-nix-action version for the README
# Get cachix/install-nix-action version for the RELEASE file
begin
install_nix_action_version = YAML.load_file(".github/workflows/release.yml")["jobs"]["update"]["steps"].find { |step| step.has_key? "uses" and step["uses"].start_with? "cachix/install-nix-action@" }["uses"].split("@", 2).last
rescue Errno::ENOENT
install_nix_action_version = "master"
end

# Update the README file
readme = render_readme(eval_id, release_name, server_url, repository, install_nix_action_version)
File.write("README.md", readme)
# Generate the RELEASE file
release_body = render_release(eval_id, release_name, server_url, repository, install_nix_action_version)
File.write("dist/RELEASE.md", release_body)

return release_name
end
Expand Down Expand Up @@ -204,7 +204,6 @@ def main(eval_id)

# Output for CI automation
if ENV.fetch("GITHUB_ACTIONS", "false") == "true"
puts "::set-output name=hydra_eval::#{eval_id}"
puts "::set-output name=nix_release::#{release_name}"

puts "::set-output name=updated::#{updated}"
Expand Down

0 comments on commit 2f45dbf

Please sign in to comment.