Skip to content

Commit

Permalink
Refactor updatecli javascript to install updatecli only (#85)
Browse files Browse the repository at this point in the history
* Remove deprecated Dockerfile

Signed-off-by: Olivier Vernin <[email protected]>

* Update updatecli config according latest refactoring

Signed-off-by: Olivier Vernin <[email protected]>

* Refactoring the GH action to only install updatecli

Signed-off-by: Olivier Vernin <[email protected]>

* Remove docker workflow

Signed-off-by: Olivier Vernin <[email protected]>

* Update dist

Signed-off-by: Olivier Vernin <[email protected]>
  • Loading branch information
olblak authored May 22, 2022
1 parent ada2e86 commit 6348984
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 195 deletions.
24 changes: 0 additions & 24 deletions .github/workflows/docker.yaml

This file was deleted.

12 changes: 3 additions & 9 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,15 @@ jobs:

- run: npm ci

# No test
# - run: npm test
test:
e2e:
name: Test Updatecli Github Action
runs-on: ubuntu-latest
steps:
- name: Git Checkout
uses: actions/checkout@v3

- name: Test local action with install-only
- name: Install Updatecli
uses: ./
with:
install-only: true

- name: Test local action without install-only
uses: ./
with:
arg: "diff --config testdata/updatecli.d/test.yaml"
run: updatecli diff --config testdata/updatecli.d/test.yaml
23 changes: 0 additions & 23 deletions Dockerfile

This file was deleted.

25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@

## Usage

Run updatecli from GitHub Action
Install Updatecli for GitHub Action

### Workflow
**Options**

WARNING: Dont enable --debug mode in Github Action as it may leak information.
`version`: Specify the Updatecli version to install. Accepted values are any valid releases such as v0.25.0

### Workflow

```yaml
name: updatecli
Expand All @@ -33,24 +35,23 @@ jobs:
- name: Checkout
uses: actions/checkout@v2

- name: Install Updatecli in local cache
- name: Install Updatecli in the runner
uses: updatecli/updatecli-action@v2
with:
install-only: true

- name: Diff
uses: updatecli/updatecli-action@v2
- name: Run Updatecli in Dry Run mode
run: updatecli diff
env:
UPDATECLI_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Apply
uses: updatecli/updatecli-action@v2
with:
arg: apply --config updatecli/updatecli.d
- name: Run Updatecli in Apply mode
run: apply --config updatecli/updatecli.d
env:
UPDATECLI_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
WARNING: Dont enable --debug mode in Github Action as it may leak information.
## License
MIT. See `LICENSE` for more details.

15 changes: 4 additions & 11 deletions action.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
---
# https://help.github.com/en/articles/metadata-syntax-for-github-actions
name: 'Updatecli Action'
description: 'GitHub Action for Updatecli, a GitDevOps Automation engine.'
name: 'Updatecli Installer'
description: 'Install a specific Updatecli version'
author: 'Updatecli'
branding:
icon: 'fast-forward'
color: 'purple'

inputs:
arg:
description: 'Arguments to pass to Updatecli'
required: false
default: diff
version:
description: 'Specify updatecli version to use'
description: 'Specify Updatecli version to use. Accepted values are any Updatecli version'
required: false
default: "v0.25.0"
install-only:
description: 'Install Updatecli'
default: false
required: false

runs:
using: 'node16'
main: 'dist/index.js'

33 changes: 7 additions & 26 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

21 changes: 0 additions & 21 deletions github-actions-entrypoint.bash

This file was deleted.

32 changes: 6 additions & 26 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ const exec = require('@actions/exec')
const path = require('path')

const version = core.getInput('version');
const arg = core.getInput('arg');
const installOnly = core.getBooleanInput('install-only')


// download Updatecli retrieve updatecli binary from Github Release
async function updatecliDownload(){
Expand Down Expand Up @@ -46,9 +43,9 @@ async function updatecliDownload(){
try {
for (let i = 0; i < updatecliPackages.length; i++) {
let updatecliPackage = updatecliPackages[i]

if (process.platform == updatecliPackage.platform && process.arch == updatecliPackage.arch) {

const downloadPath = await tool.downloadTool(updatecliPackage.url);

core.info(`Downloading ${updatecliPackage.url}`)
Expand All @@ -74,7 +71,7 @@ async function updatecliDownload(){

core.debug(`Extracting file to ${updatecliExtractedFolder} ...`);

core.info('Adding to the cache ...');
core.debug('Adding to the cache ...');
const cachedPath = await tool.cacheDir(updatecliExtractedFolder, 'updatecli', version, process.arch);
core.addPath(cachedPath);

Expand All @@ -101,30 +98,13 @@ async function updatecliVersion(){
}
}

async function updatecliRun(){
try {
core.info("Run Updatecli")
const updatecliDirectory = tool.find('updatecli', version, process.arch);
core.addPath(updatecliDirectory);
await exec.exec(`updatecli ${arg}`);
} catch (error) {
core.setFailed(error.message);
}
}

async function run() {

if (installOnly) {
await updatecliDownload()
await updatecliVersion();
process.exit(0)
}

await updatecliDownload()
await updatecliVersion();
await updatecliRun();
process.exit(0)

process.exit(0);
}

run()

run()
67 changes: 25 additions & 42 deletions updatecli/updatecli.d/updatecli.yaml
Original file line number Diff line number Diff line change
@@ -1,60 +1,43 @@
title: Bump updatecli version
title: "Bump updatecli version"

scms:
default:
kind: github
kind: "github"
spec:
user: updatecli
email: [email protected]
owner: updatecli
repository: updatecli-action
username: github-actions
token: {{requiredEnv "UPDATECLI_GITHUB_TOKEN"}}
branch: main
user: "updatecli"
email: "[email protected]"
owner: "updatecli"
repository: "updatecli-action"
username: "github-actions"
token: '{{requiredEnv "UPDATECLI_GITHUB_TOKEN"}}'
branch: "v2"

sources:
lastVersion:
name: Get latest updatecli version
kind: githubRelease
spec:
owner: updatecli
repository: updatecli
token: {{requiredEnv "UPDATECLI_GITHUB_TOKEN"}}

conditions:
dockerImage:
name: Ensure that the image docker image tag is published
kind: dockerImage
spec:
image: "ghcr.io/updatecli/updatecli"
architecture: amd64
dockerfile:
name: "Test if ARG UPDATECLI_VERSION is set"
kind: dockerfile
updatecli:
name: "Get latest updatecli version"
kind: "githubrelease"
spec:
file: Dockerfile
instruction:
keyword: "ARG"
matcher: "UPDATECLI_VERSION"
owner: "updatecli"
repository: "updatecli"
token: '{{requiredEnv "UPDATECLI_GITHUB_TOKEN"}}'

targets:
dockerfile:
name: "Update the value of ARG UPDATECLI_VERSION in the Dockerfile"
kind: dockerfile
action:
name: "Bump updatecli version in action.yaml"
kind: yaml
scmid: default
sourceid: updatecli
spec:
file: Dockerfile
instruction:
keyword: "ARG"
matcher: "UPDATECLI_VERSION"
scmID: default
file: "action.yaml"
key: "inputs.version.default"

pullrequests:
default:
kind: github
title: 'Bump updatecli version to {{ source "lastVersion" }}'
scmID: default
title: 'Bump updatecli version to {{ source "updatecli" }}'
scmid: default
targets:
- dockerfile
- action
spec:
labels:
- dependencies
Expand Down

0 comments on commit 6348984

Please sign in to comment.