Skip to content

Commit 8d10cff

Browse files
lens0021claude
andauthored
feat: Add support for building Amber from source (#69)
* feat: Add support for building Amber from source * Add a test * Use GITHUB_TOKEN * fix: Replace cargo -C flag with cd command for stability The -C flag in cargo is unstable and requires the nightly toolchain. Changed to use `cd && cargo build` instead for better compatibility. This fixes the failing test-repository-ref CI check. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * security: Fix template injection in test workflow Pass step outputs through environment variables instead of direct template expansion to prevent potential code injection attacks. This addresses the zizmor security warning about template-injection. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * security: Fix template injection vulnerabilities in action.yaml Pass all GitHub Actions template expansions through environment variables instead of direct shell interpolation to prevent potential code injection attacks. Changes: - Determine source directory: Pass inputs and step outputs via env vars - Checkout Amber source: Pass repository URL and ref via env vars - Main step: Pass action path via env var This addresses zizmor template-injection warnings in the composite action. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * Restore comment * build * refactor: Simplify Rust installation error message Make the error message less prescriptive by removing the specific rustup command. Now just hints that Rust toolchain setup may be needed. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * docs: Add documentation for building from source Add comprehensive documentation for the new amber-repository-ref and amber-repository-url inputs, including: - Parameter descriptions in the usage section - Multiple examples showing different use cases - Note about Rust toolchain requirements Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 2a75b8a commit 8d10cff

File tree

5 files changed

+382
-187
lines changed

5 files changed

+382
-187
lines changed

.github/workflows/test.yaml

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,25 @@ jobs:
8888

8989
- run: ./amber --version
9090

91+
test-repository-ref:
92+
name: Test amber-repository-ref
93+
runs-on: ubuntu-latest
94+
steps:
95+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
96+
with:
97+
persist-credentials: false
98+
99+
- uses: ./
100+
with:
101+
amber-repository-ref: 3742194594cfdf18e034658d1f58a93b3143bbd7
102+
103+
- run: |
104+
which amber
105+
amber --version | grep -q 3742194
106+
echo 'echo("Hello, Amber!")' > test.ab
107+
amber build test.ab
108+
bash test.sh
109+
91110
test-output:
92111
name: Test amber-path output
93112
runs-on: ubuntu-latest
@@ -101,13 +120,15 @@ jobs:
101120
with:
102121
amber-version: 0.5.1-alpha
103122

104-
- run: |
105-
echo "Amber path output: ${{ steps.setup.outputs.amber-path }}"
106-
if [ -z "${{ steps.setup.outputs.amber-path }}" ]; then
123+
- env:
124+
AMBER_PATH: ${{ steps.setup.outputs.amber-path }}
125+
run: |
126+
echo "Amber path output: $AMBER_PATH"
127+
if [ -z "$AMBER_PATH" ]; then
107128
echo "Error: amber-path output is empty"
108129
exit 1
109130
fi
110-
if [ ! -x "${{ steps.setup.outputs.amber-path }}" ]; then
131+
if [ ! -x "$AMBER_PATH" ]; then
111132
echo "Error: amber-path does not point to an executable file"
112133
exit 1
113134
fi

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ See [action.yaml](action.yaml)
2727
# Default: 0.5.1-alpha
2828
amber-version: ""
2929

30+
# Git repository URL to clone Amber from when building from source.
31+
# Default: https://github.com/amber-lang/amber.git
32+
amber-repository-url: ""
33+
34+
# Git ref (commit SHA, branch, or tag) to build Amber from source.
35+
# If provided, this overrides 'amber-version' and builds from source.
36+
# Examples: main, v0.5.0-alpha, 3742194594cfdf18e034658d1f58a93b3143bbd7
37+
# Default: "" (uses pre-built binaries)
38+
amber-repository-ref: ""
39+
3040
# Whether to cache Amber binaries
3141
# Default: true
3242
enable-cache: ""
@@ -94,6 +104,35 @@ jobs:
94104
run: echo "Amber installed at ${{ steps.setup-amber.outputs.amber-path }}"
95105
```
96106

107+
**Building from source:**
108+
109+
```yaml
110+
- uses: lens0021/setup-amber@v2
111+
with:
112+
# Build from a specific commit
113+
amber-repository-ref: 3742194594cfdf18e034658d1f58a93b3143bbd7
114+
```
115+
116+
```yaml
117+
- uses: lens0021/setup-amber@v2
118+
with:
119+
# Build from a branch
120+
amber-repository-ref: main
121+
```
122+
123+
```yaml
124+
- uses: lens0021/setup-amber@v2
125+
with:
126+
# Build from a custom repository fork
127+
amber-repository-url: https://github.com/myusername/amber.git
128+
amber-repository-ref: my-feature-branch
129+
```
130+
131+
> [!NOTE]
132+
> Building from source requires Rust and Cargo to be available in the environment.
133+
> GitHub Actions runners include these by default, but if you're using a custom
134+
> runner, you may need to install the Rust toolchain first.
135+
97136
## License
98137

99138
This project is licensed under the GNU General Public License v3.0 - see the [LICENSE](LICENSE) file for details.

action.yaml

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ inputs:
77
amber-version:
88
description: The version of Amber to install.
99
default: 0.5.1-alpha
10+
amber-repository-url:
11+
description: >-
12+
The Git repository URL to clone Amber from when building from source.
13+
Defaults to the official Amber repository.
14+
default: https://github.com/amber-lang/amber.git
15+
amber-repository-ref:
16+
description: >-
17+
A Git ref (commit SHA, branch name, or tag name) to build Amber from source.
18+
If provided, this overrides 'amber-version' and triggers a build from source.
19+
default: ""
1020
enable-cache:
1121
description: Whether to cache Amber binaries.
1222
default: true
@@ -42,16 +52,67 @@ runs:
4252
} >> "$GITHUB_OUTPUT"
4353
- name: Cache Amber binaries
4454
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
55+
id: amber-cache
4556
if: inputs.enable-cache
4657
with:
4758
path: ${{ steps.cache-path.outputs.amber_cache_path }}/amber
48-
key: setup-amber-${{ runner.os }}-${{ runner.arch }}-${{ inputs.amber-version }}
59+
key: >-
60+
setup-amber-${{ runner.os }}-${{ runner.arch }}-${{ inputs.amber-repository-ref || inputs.amber-version }}
61+
- name: Determine source directory
62+
if: inputs.amber-repository-ref != '' && steps.amber-cache.outputs.cache-hit != 'true'
63+
id: source-dir
64+
shell: bash
65+
env:
66+
ENABLE_CACHE: ${{ inputs.enable-cache }}
67+
CACHE_PATH: ${{ steps.cache-path.outputs.amber_cache_path }}
68+
RUNNER_TEMP: ${{ runner.temp }}
69+
run: |
70+
if [ "$ENABLE_CACHE" = "true" ]; then
71+
src_dir="$CACHE_PATH/amber-source"
72+
else
73+
src_dir="$RUNNER_TEMP/amber-source"
74+
fi
75+
echo "src_dir=$src_dir" >> "$GITHUB_OUTPUT"
76+
- name: Checkout Amber source
77+
if: inputs.amber-repository-ref != '' && steps.amber-cache.outputs.cache-hit != 'true'
78+
shell: bash
79+
env:
80+
SOURCE_DIR: ${{ steps.source-dir.outputs.src_dir }}
81+
REPO_URL: ${{ inputs.amber-repository-url }}
82+
REPO_REF: ${{ inputs.amber-repository-ref }}
83+
run: |
84+
dest_dir="$SOURCE_DIR"
85+
echo "::debug::Checking out Amber source to $dest_dir"
86+
if [ -d "$dest_dir/.git" ]; then
87+
echo "Source already exists in $dest_dir"
88+
else
89+
mkdir -p "$dest_dir"
90+
cd "$dest_dir"
91+
git init
92+
# Use the token for authentication if it's a GitHub URL
93+
url="$REPO_URL"
94+
if [[ "$url" == "https://github.com/"* ]]; then
95+
url="${url/https:\/\/github.com\//https://x-access-token:$GITHUB_TOKEN@github.com/}"
96+
fi
97+
git remote add origin "$url"
98+
git fetch --depth 1 origin "$REPO_REF"
99+
git checkout FETCH_HEAD
100+
fi
101+
- name: Cache Rust build artifacts
102+
uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2.8.2
103+
if: inputs.amber-repository-ref != '' && steps.amber-cache.outputs.cache-hit != 'true'
104+
with:
105+
workspaces: ${{ steps.source-dir.outputs.src_dir }} -> target
49106
- id: main
50107
shell: bash
51108
env:
109+
ACTION_PATH: ${{ github.action_path }}
52110
SETUP_AMBER_CACHE_PATH: ${{ steps.cache-path.outputs.amber_cache_path }}
53111
SETUP_AMBER_BIN_PATH: ${{ inputs.bin-path }}
54112
SETUP_AMBER_VERSION: ${{ inputs.amber-version }}
113+
SETUP_AMBER_REPOSITORY_URL: ${{ inputs.amber-repository-url }}
114+
SETUP_AMBER_REPOSITORY_REF: ${{ inputs.amber-repository-ref }}
115+
SETUP_AMBER_SOURCE_DIR: ${{ steps.source-dir.outputs.src_dir }}
55116
run: |
56117
# Download Amber binary
57-
bash "${{ github.action_path }}/dist/main.sh"
118+
bash "$ACTION_PATH/dist/main.sh"

0 commit comments

Comments
 (0)