-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add parse-snapcraft-yaml action
- Loading branch information
Showing
10 changed files
with
152 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# snapcrafters/ci/parse-snapcraft-yaml | ||
|
||
This action is more for use internally than otherwise. It's purpose is to either find a snapcraft.yaml file from a list of known common locations in a repository, or take the path to a snapcraft.yaml, then parse some information from it and provide that information as outputs. | ||
|
||
You only need to specify the `snapcraft-yaml-path` input if your `snapcraft.yaml` is not in one of the following locations: | ||
|
||
- `.snapcraft.yaml` | ||
- `build-aux/snap/snapcraft.yaml` | ||
- `snap/snapcraft.yaml` | ||
- `snapcraft.yaml` | ||
|
||
## Usage | ||
|
||
```yaml | ||
# ... | ||
jobs: | ||
parse-snapcraft-yaml: | ||
name: 🖥 Parse the snapcraft yaml file | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Find and parse snapcraft.yaml | ||
id: snapcraft-yaml | ||
uses: snapcrafters/ci/parse-snapcraft-yaml@main | ||
``` | ||
## API | ||
### Inputs | ||
| Key | Description | Required | Default | | ||
| --------------------- | -------------------------------------- | :------: | :------ | | ||
| `snapcraft-yaml-path` | The path to the `snapcraft.yaml` file. | N | | | ||
|
||
### Outputs | ||
|
||
| Key | Description | Example | | ||
| ----------- | ------------------------------------------------------ | --------------------- | | ||
| `snap_name` | The name of the snap as declared in the snapcraft.yaml | `signal-desktop` | | ||
| `version` | The version declared in the snapcraft.yaml file | `6.41.0` | | ||
| `yaml_path` | The path to the snapcraft.yaml for the project | `snap/snapcraft.yaml` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
name: Parse Snapcraft YAML | ||
description: Finds the snapcraft yaml for a repo and parses key information from it. | ||
author: Snapcrafters | ||
branding: | ||
icon: code | ||
color: orange | ||
|
||
inputs: | ||
snapcraft-yaml-path: | ||
description: "Custom path to snapcraft.yaml for when it is not in the default location." | ||
required: false | ||
|
||
outputs: | ||
snap-name: | ||
description: "The name of the snap as declared in the snapcraft.yaml" | ||
value: ${{ steps.parse.outputs.snap-name }} | ||
version: | ||
description: "The version declared in the snapcraft.yaml file" | ||
value: ${{ steps.parse.outputs.version }} | ||
yaml-path: | ||
description: "The path to the snapcraft.yaml for the project" | ||
value: ${{ steps.parse.outputs.yaml-path }} | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- name: Checkout the source | ||
uses: actions/checkout@v4 | ||
|
||
- name: Find and parse snapcraft.yaml | ||
id: parse | ||
shell: bash | ||
run: | | ||
if [[ -n "${{ inputs.snapcraft-yaml-path }}" ]]; then | ||
yaml_path="${{ inputs.snapcraft-yaml-path }}" | ||
else | ||
common_paths=( | ||
".snapcraft.yaml" | ||
"build-aux/snap/snapcraft.yaml" | ||
"snap/snapcraft.yaml" | ||
"snapcraft.yaml" | ||
) | ||
for file in "${common_paths[@]}"; do | ||
if [[ -f "$file" ]]; then | ||
yaml_path="$file" | ||
fi | ||
done | ||
fi | ||
if [[ -z "${yaml_path}" ]]; then | ||
echo "No snapcraft.yaml found" | ||
exit 1 | ||
fi | ||
echo "yaml-path=${yaml_path}" >> "$GITHUB_OUTPUT" | ||
echo "snap-name=$(yq -r '.name' "$yaml_path")" >> "$GITHUB_OUTPUT" | ||
echo "version=$(yq -r '.version' "$yaml_path")" >> "$GITHUB_OUTPUT" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,40 +46,19 @@ runs: | |
git config --global user.email "[email protected]" | ||
git config --global user.name "Github Actions" | ||
- name: Find the snapcraft.yaml path | ||
id: yaml-path | ||
shell: bash | ||
run: | | ||
if [[ -n "${{ inputs.snapcraft-yaml-path }}" ]]; then | ||
yaml_path="${{ inputs.snapcraft-yaml-path }}" | ||
else | ||
snapcraft_yaml_paths=( | ||
"snap/snapcraft.yaml" | ||
"snapcraft.yaml" | ||
"build-aux/snap/snapcraft.yaml" | ||
".snapcraft.yaml" | ||
) | ||
for file in "${snapcraft_yaml_paths[@]}"; do | ||
if [[ -f "$file" ]]; then | ||
yaml_path="$file" | ||
fi | ||
done | ||
fi | ||
if [[ -z "${yaml_path}" ]]; then | ||
echo "No snapcraft.yaml found" | ||
exit 1 | ||
fi | ||
echo "yaml-path=${yaml_path}" >> "$GITHUB_OUTPUT" | ||
echo "snap-name=$(yq -r '.name' "$yaml_path")" >> "$GITHUB_OUTPUT" | ||
- name: Find and parse snapcraft.yaml | ||
id: snapcraft-yaml | ||
uses: snapcrafters/ci/parse-snapcraft-yaml@main | ||
with: | ||
snapcraft-yaml-path: ${{ inputs.snapcraft-yaml-path }} | ||
|
||
- name: Build the snap (${{ inputs.architecture }}) | ||
id: build | ||
shell: bash | ||
env: | ||
yaml_path: ${{ steps.yaml-path.outputs.yaml-path }} | ||
name: ${{ steps.yaml-path.outputs.snap-name }} | ||
arch: ${{ inputs.architecture }} | ||
name: ${{ steps.snapcraft-yaml.outputs.snap-name }} | ||
yaml_path: ${{ steps.snapcraft-yaml.outputs.yaml-path }} | ||
run: | | ||
# Remove the architecture definition from the snapcraft.yaml due to: | ||
# https://bugs.launchpad.net/snapcraft/+bug/1885150 | ||
|
@@ -105,7 +84,7 @@ runs: | |
id: parse | ||
shell: bash | ||
env: | ||
yaml_path: ${{ steps.yaml-path.outputs.yaml-path }} | ||
yaml_path: ${{ steps.snapcraft-yaml.outputs.yaml-path }} | ||
run: | | ||
# Populate defaults | ||
echo "classic=false" >> "$GITHUB_OUTPUT" | ||
|
Oops, something went wrong.