Skip to content

Commit

Permalink
Fix errors in jobs (#63)
Browse files Browse the repository at this point in the history
* Add extra parameters to release and upload jobs

* Some extra fixes

* Fix typo

* Add release test

* Add debug

* Remove quotes from @

* Change order of params

* Fix error

* Disable shellcheck

* Change script release structure

* Update rlease test to verify additional_args

* Update to fix additional args

* Use a different arg to make it more simple
  • Loading branch information
marboledacci authored Nov 27, 2024
1 parent 1291e52 commit f64c929
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 19 deletions.
22 changes: 15 additions & 7 deletions .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: 2.1
orbs:
github-cli: {}
orb-tools: circleci/[email protected]
orb-tools: circleci/orb-tools@12.2.0

filters: &filters
tags:
Expand Down Expand Up @@ -65,6 +65,14 @@ workflows:
parameters:
executor: ["docker-x86-debian", "apple-silicon-14", "apple-silicon-15", "linuxvm-arm-ubuntu-2004", "linuxvm-x86-ubuntu-2004", "linuxvm-arm-ubuntu-2204", "linuxvm-x86-ubuntu-2204", "linuxvm-arm-ubuntu-2404", "linuxvm-x86-ubuntu-2404"]
version: [2.27.0, 2.40.0, "latest"] # 2.27.0 is the last version that uses ".tar.gz" instead of ".zip" for macOS
- github-cli/release:
tag: "test-release-$CIRCLE_SHA1"
title: Test
prerelease: true
files: README.md
context: orb-developer
token: GHI_TOKEN
additional_args: --generate-notes
- orb-tools/pack:
filters: *release-filters
- orb-tools/publish:
Expand All @@ -91,22 +99,22 @@ executors:
resource_class: macos.m1.medium.gen1
linuxvm-arm-ubuntu-2004:
machine:
image: ubuntu-2004:2024.05.1
image: ubuntu-2004:2024.08.1
resource_class: arm.medium
linuxvm-x86-ubuntu-2004:
machine:
image: ubuntu-2004:2024.05.1
image: ubuntu-2004:2024.08.1
linuxvm-arm-ubuntu-2204:
machine:
image: ubuntu-2204:2024.05.1
image: ubuntu-2204:2024.08.1
resource_class: arm.medium
linuxvm-x86-ubuntu-2204:
machine:
image: ubuntu-2204:2024.05.1
image: ubuntu-2204:2024.08.1
linuxvm-arm-ubuntu-2404:
machine:
image: ubuntu-2404:2024.05.1
image: ubuntu-2404:2024.08.1
resource_class: arm.medium
linuxvm-x86-ubuntu-2404:
machine:
image: ubuntu-2404:2024.05.1
image: ubuntu-2404:2024.08.1
3 changes: 2 additions & 1 deletion src/commands/clone.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
description: |
A GitHub specific alternative to CircleCI's native "checkout" command.
Use the GitHub CLI to clone the current repository, or specify an alternative repo via parameters.
https://cli.github.com/manual/gh_repo_clone
https://cli.github.com/manual/gh_repo_clone.
This requires read:org permissions on a private repo.
parameters:
repo:
type: string
Expand Down
4 changes: 3 additions & 1 deletion src/commands/install.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
description: Install the gh cli without authenticating or configuring. This command should be run before invoking the gh cli.
description: |
Install the gh cli without authenticating or configuring. This command should be run before invoking the gh cli.
This requires read:org permissions on private repos.
parameters:
version:
type: string
Expand Down
2 changes: 1 addition & 1 deletion src/jobs/pr-merge.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
description: >
Merge pull request to target branch.
See more at https://cli.github.com/manual/gh_pr_merge.
This requires write:discussion permissions.
docker:
- image: cimg/base:stable

Expand Down
20 changes: 18 additions & 2 deletions src/jobs/release.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
description: >
Create a new GitHub Release for a repository.
Specify a tag with the `tag` parameter (required). If a matching git tag does not yet exist, one will automatically get created from the latest state of the default branch.
This requires write:packages permissions.
docker:
- image: cimg/base:stable

Expand Down Expand Up @@ -51,12 +51,27 @@ parameters:
description: |
Enter the name of the environment variable containing the GitHub Personal Access token to be used for authentication.
It is recommended for CI processes that you create a "machine" user on GitHub.com with the needed permissions, rather than using your own.
dir:
type: string
default: "."
description: |
Select the path to clone into. By default the current path will be selected, which is dictated by the job's "working_directory".
The release will be done from this path.
clone:
type: boolean
default: true
description: Whether or not clone the repo. Defaults to true. Set to false if you already cloned the repo.
steps:
- setup:
version: <<parameters.version>>
token: <<parameters.token>>
hostname: <<parameters.hostname>>
- clone
- when:
condition: <<parameters.clone>>
steps:
- clone:
dir: <<parameters.dir>>
hostname: <<parameters.hostname>>
- run:
name: "Creating a <<#parameters.draft>><<parameters.draft>> <</parameters.draft>>GitHub Release"
environment:
Expand All @@ -69,4 +84,5 @@ steps:
PARAM_GH_FILES: <<parameters.files>>
PARAM_GH_TITLE: <<parameters.title>>
PARAM_GH_ARGS: <<parameters.additional_args>>
PARAM_DIR: <<parameters.dir>>
command: <<include(scripts/release.sh)>>
20 changes: 18 additions & 2 deletions src/jobs/upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ description: >
Upload assets to an existing GitHub Release.
Specify a tag matching the release with the `tag` parameter (required).
See more at https://cli.github.com/manual/gh_release_upload.
This requires write:packages permissions.
docker:
- image: cimg/base:stable

Expand Down Expand Up @@ -38,11 +38,26 @@ parameters:
type: string
default: "2.20.2"
description: Specify the full semver versioned tag to use for the GitHub CLI installation.
dir:
type: string
default: "."
description: |
Select the path to clone into. By default the current path will be selected, which is dictated by the job's "working_directory".
The upload will be done from this path.
clone:
type: boolean
default: true
description: Whether or not clone the repo. Defaults to true. Set to false if you already cloned the repo.

steps:
- install:
version: <<parameters.version>>
- clone
- when:
condition: <<parameters.clone>>
steps:
- clone:
dir: <<parameters.dir>>
hostname: <<parameters.hostname>>
- run:
name: "Uploading assets to GitHub Release"
environment:
Expand All @@ -51,4 +66,5 @@ steps:
ORB_EVAL_HOSTNAME: <<parameters.hostname>>
ORB_EVAL_TAG: <<parameters.tag>>
ORB_ENV_TOKEN: <<parameters.token>>
PARAM_DIR: <<parameters.dir>>
command: <<include(scripts/upload.sh)>>
12 changes: 8 additions & 4 deletions src/scripts/release.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash
# Get auth token
set -x
cd "$PARAM_DIR" || exit
export GITHUB_TOKEN=${!PARAM_GH_TOKEN}
[ -z "$GITHUB_TOKEN" ] && echo "A GitHub token must be supplied. Check the \"token\" parameter." && exit 1
echo "export GITHUB_TOKEN=\"${GITHUB_TOKEN}\"" >>"$BASH_ENV"
Expand All @@ -10,6 +12,9 @@ if [ "$PARAM_GH_HOSTNAME" == 1 ]; then
echo "export GITHUB_HOSTNAME=\"${PARAM_GH_HOSTNAME}\"" >>"$BASH_ENV"
fi

if [ -n "$PARAM_GH_ARGS" ]; then
set -- "$@" "$PARAM_GH_ARGS"
fi
if [ "$PARAM_GH_DRAFT" == 1 ]; then
set -- "$@" --draft
fi
Expand All @@ -23,13 +28,12 @@ if [ -n "$PARAM_GH_TITLE" ]; then
set -- "$@" --title "$PARAM_GH_TITLE"
fi
if [ -n "$PARAM_GH_FILES" ]; then
set -- "$@" " $PARAM_GH_FILES"
set -- "$@" "$PARAM_GH_FILES"
fi

set -- "$@" --repo "$(git config --get remote.origin.url)"

# shellcheck disable=SC2086
# shellcheck disable=SC2086,SC2068
gh release create \
"$PARAM_GH_TAG" \
$PARAM_GH_ARGS \
"$@"
$@
2 changes: 1 addition & 1 deletion src/scripts/upload.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash

cd "$PARAM_DIR" || exit
additional_args="$(eval printf '%s\\n' "$ORB_EVAL_ADDITIONAL_ARGS")"
files="$(eval printf '%s\\n' "$ORB_EVAL_FILES")"
hostname="$(eval printf '%s' "$ORB_EVAL_HOSTNAME")"
Expand Down

0 comments on commit f64c929

Please sign in to comment.