feat: add release workflow (#2)

This commit is contained in:
seth 2023-07-19 02:51:10 +00:00 committed by GitHub
parent 16bd754a82
commit a9de6744a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 90 additions and 92 deletions

30
.github/workflows/release.yml vendored Normal file
View file

@ -0,0 +1,30 @@
name: Release
on:
release:
types: [published, edited]
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
ref: ${{ github.event.release.tag_name }}
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v3
with:
cache: pnpm
cache-dependency-path: pnpm-lock.yaml
- name: Build
run: pnpm install && pnpm build
- uses: JasonEtco/build-and-tag-action@v2
env:
GITHUB_TOKEN: ${{ github.token }}

View file

@ -3,7 +3,6 @@ name: "Test"
on: on:
push: push:
branches: ["main"] branches: ["main"]
pull_request:
workflow_call: workflow_call:
workflow_dispatch: workflow_dispatch:
@ -19,12 +18,18 @@ jobs:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v3 uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v3
with:
cache: pnpm
cache-dependency-path: pnpm-lock.yaml
- name: Build
run: pnpm install && pnpm build
- name: Install Nix - name: Install Nix
uses: cachix/install-nix-action@v22 uses: cachix/install-nix-action@v22
- name: Setup nixpkgs
run: nix-channel --add https://nixos.org/channels/nixpkgs-unstable && nix-channel --update
- name: Setup Attic Cache - name: Setup Attic Cache
uses: ./ uses: ./
with: with:
@ -32,5 +37,5 @@ jobs:
cache: ${{ secrets.ATTIC_CACHE }} cache: ${{ secrets.ATTIC_CACHE }}
token: ${{ secrets.ATTIC_TOKEN }} token: ${{ secrets.ATTIC_TOKEN }}
- name: Build - name: Build Nix Package
run: nix-build test.nix run: nix build -f test.nix

View file

@ -1,4 +1,4 @@
{ {
"useTabs": true, "useTabs": true,
"printWidth": 120 "printWidth": 120
} }

View file

@ -18,5 +18,5 @@ inputs:
runs: runs:
using: "node16" using: "node16"
main: "dist/index.js" main: "dist/index.js"
post: "dist/post.js" post: "dist/index.js"
post-if: "success()" post-if: "success()"

29
dist/index.js vendored

File diff suppressed because one or more lines are too long

9
dist/post.js vendored

File diff suppressed because one or more lines are too long

View file

@ -1,24 +1,24 @@
{ {
"name": "@ryanccn/attic-action", "name": "@ryanccn/attic-action",
"version": "0.1.0", "main": "dist/index.js",
"description": "Cache Nix derivations with attic", "description": "Cache Nix derivations with attic",
"scripts": { "scripts": {
"build": "esbuild src/index.ts src/post.ts --outdir=dist --platform=node --format=cjs --bundle --minify-whitespace --minify-syntax", "build": "esbuild src/index.ts --outdir=dist --platform=node --format=cjs --bundle --minify-whitespace --minify-syntax",
"format": "prettier --write ." "format": "prettier --write ."
}, },
"keywords": [], "keywords": [],
"author": "Ryan Cao <hello@ryanccn.dev>", "author": "Ryan Cao <hello@ryanccn.dev>",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/core": "^1.10.0", "@actions/core": "^1.10.0",
"@actions/exec": "^1.1.1", "@actions/exec": "^1.1.1",
"ofetch": "^1.1.1" "ofetch": "^1.1.1"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^16.18.38", "@types/node": "^16.18.38",
"esbuild": "^0.18.14", "esbuild": "^0.18.14",
"prettier": "3.0.0", "prettier": "3.0.0",
"typescript": "^5.1.6" "typescript": "^5.1.6"
}, },
"packageManager": "pnpm@8.6.9" "packageManager": "pnpm@8.6.9"
} }

View file

@ -1,9 +1,18 @@
import { install } from "./stages/install"; import { install } from "./stages/install";
import { configure } from "./stages/configure"; import { configure } from "./stages/configure";
import { push } from "./stages/push.ts";
import { getState, saveState } from "@actions/core";
const isPost = !!getState("isPost");
const main = async () => { const main = async () => {
await install(); await install();
await configure(); await configure();
}; };
main(); if (!isPost) {
saveState("isPost", true);
main();
} else {
push();
}

View file

@ -1,7 +0,0 @@
import { push } from "./stages/push";
const main = async () => {
await push();
};
main();

View file

@ -16,7 +16,6 @@ export const install = async () => {
if (!r.ok) { if (!r.ok) {
core.setFailed(`Action failed with error: ${r.statusText}`); core.setFailed(`Action failed with error: ${r.statusText}`);
core.endGroup(); core.endGroup();
process.exit(1); process.exit(1);
} }

View file

@ -1,16 +1,16 @@
{ {
"compilerOptions": { "compilerOptions": {
"strict": true, "strict": true,
"downlevelIteration": true, "downlevelIteration": true,
"module": "esnext", "module": "esnext",
"target": "esnext", "target": "esnext",
"moduleResolution": "node", "moduleResolution": "node",
"esModuleInterop": true, "esModuleInterop": true,
"allowSyntheticDefaultImports": true, "allowSyntheticDefaultImports": true,
"isolatedModules": true, "isolatedModules": true,
"skipLibCheck": true, "skipLibCheck": true,
"noEmit": true "noEmit": true
}, },
"include": ["**/*.ts"], "include": ["**/*.ts"],
"exclude": ["node_modules", "**/node_modules/*"] "exclude": ["node_modules", "**/node_modules/*"]
} }