{"id":18379487,"url":"https://github.com/iinm/bash-ci","last_synced_at":"2025-04-06T22:32:33.210Z","repository":{"id":56702577,"uuid":"208608448","full_name":"iinm/bash-ci","owner":"iinm","description":"Bash scripts for CI","archived":false,"fork":false,"pushed_at":"2020-10-24T05:53:56.000Z","size":104,"stargazers_count":8,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-22T07:44:42.677Z","etag":null,"topics":["bash","ci","github","gitlab"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iinm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-15T14:45:30.000Z","updated_at":"2024-12-01T08:57:38.000Z","dependencies_parsed_at":"2022-08-15T23:40:14.090Z","dependency_job_id":null,"html_url":"https://github.com/iinm/bash-ci","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iinm%2Fbash-ci","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iinm%2Fbash-ci/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iinm%2Fbash-ci/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iinm%2Fbash-ci/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iinm","download_url":"https://codeload.github.com/iinm/bash-ci/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247563902,"owners_count":20958971,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","ci","github","gitlab"],"created_at":"2024-11-06T00:38:10.681Z","updated_at":"2025-04-06T22:32:32.765Z","avatar_url":"https://github.com/iinm.png","language":"Shell","readme":"# Bash scripts for CI\n\n![](https://github.com/iinm/bash-ci/workflows/verify/badge.svg?branch=master)\n\n\n## Requirements\n\n- [Bash](https://www.gnu.org/software/bash/)\n- [cURL](https://curl.haxx.se/)\n- [jq](https://stedolan.github.io/jq/)\n\n\n## Docker\n\nRun command on container. (Assume you have Dockerfile)\n```sh\n./with_dockerfile --verbose make lint\n```\n\n```sh\nmkdir -p ./tmp/with_dockerfile_exmaple\necho \"FROM busybox\" \u003e ./tmp/with_dockerfile_exmaple/Dockerfile\n\n./with_dockerfile --verbose --build-path ./tmp/with_dockerfile_exmaple ls -lh\n```\n\nRun command on container and copy artifacts from docker volume to host directory.\n```sh\nmkdir -p ./tmp/with_dockerfile_exmaple\necho \"FROM busybox\" \u003e ./tmp/with_dockerfile_exmaple/Dockerfile\n\n./with_dockerfile --verbose --build-path ./tmp/with_dockerfile_exmaple \\\n  --task-id 'ls' --artifact out.txt sh -c 'ls -lh \u003e out.txt'\n\ncat ./artifacts/ls/out.txt\n```\n\nUse docker volume as cache.\n```sh\nmkdir -p ./tmp/with_dockerfile_exmaple\necho \"FROM node:current-alpine\" \u003e ./tmp/with_dockerfile_exmaple/Dockerfile\n\n./with_dockerfile --verbose --build-path ./tmp/with_dockerfile_exmaple \\\n  --task-id 'node-example' --run-opts '-v npm-user-cache:/root/.npm' \\\n  sh -c 'npm install ramda; ls -lh ./node_modules'\n```\n\n\n## Git\n\nRun command when branch is pushed.\n```sh\ncat \u003e ./tmp/hooks.ltsv \u003c\u003c 'HOOKS'\nhook_id:echo-example\trefs_pattern:master\tcmd:echo \"$REF - $COMMIT_SHA\"\nhook_id:jenkins-example\trefs_pattern:master\tcmd:curl -vsSf -X POST -u \"$JENKINS_AUTH\" -F \"BRANCH=$REF\" -F \"$COMMIT_SHA\" http://127.0.0.1:8080/jenkins/job/template/buildWithParameters\nHOOKS\n\ngit ls-remote https://github.com/iinm/bash-ci | ./git.bash hook_push --logdir ./tmp/hook_log --hooks ./tmp/hooks.ltsv\n```\n\n- `--logdir` : stdout / stderr of cmd will be output this directory\n- `--hooks`  : hooks ltsv file\n  - `hook_id` : Unique ID (Used as a part of log file name)\n  - `refs_pattern` : pattern to filter branches or tags\n  - `cmd`     : Command you want to execute when branch is pushed; Environment variables `$REF`, and `$COMMIT_SHA` are automatically set\n\n\n## GitLab\n\nSet environment variables.\n```sh\nexport GITLAB_BASE_URL=\"https://gitlab.com\"\nexport GITLAB_PRIVATE_TOKEN=\"your token\"   # https://gitlab.com/profile/personal_access_tokens\nexport GITLAB_PROJECT_ID=\"your project id\"\n```\n\nRun command when merge request is created / updated.\n```sh\ncat \u003e ./tmp/hooks.ltsv \u003c\u003c 'HOOKS'\nhook_id:echo-example\tfilter:.labels | map(. == \"skip-ci\") | any | not\tcmd:echo \"[$MERGE_REQUEST_IID] $SOURCE_BRANCH -\u003e $TARGET_BRANCH ($MERGE_REQUEST_URL)\"\nhook_id:jenkins-example\tfilter:.labels | map(. == \"skip-ci\") | any | not\tcmd:curl --verbose --silent --show-error --fail -X POST -u $JENKINS_AUTH \"http://localhost/job/test/build\" -F json=\"$(./gitlab.bash merge_request_json_for_jenkins)\"\nHOOKS\n\n./gitlab.bash list_merge_requests \\\n  | ./gitlab.bash hook_merge_requests --logdir ./tmp/hook_log --hooks ./tmp/hooks.ltsv\n```\n\n- `--logdir` : stdout / stderr of cmd will be output this directory\n- `--hooks`  : hooks ltsv file\n  - `hook_id` : Unique ID (Used as a part of log file name)\n  - `filter`  : [jq](https://stedolan.github.io/jq/manual/) filter to select merge request to hook\n  - `cmd`     : Command you want to execute when merge request is created / updated; Environment variables `$MERGE_REQUEST_IID`, `$SOURCE_BRANCH`, `$TARGET_BRANCH`, and `$MERGE_REQUEST_URL` are automatically set\n\nRun command as GitLab Pipeline job.\n```sh\n./with_gitlab_pipeline --commit-sha \"$(git log -n 1 --pretty=format:'%H')\" \\\n  --build-system-name \"Jenkins\" --build-url \"http://localhost/jenkins/job/test/1\" \\\n  make lint test\n```\n\nRun command and comment result on merge request.\n```sh\n./with_gitlab_mr_comment --iid \"3\" \\\n  --comment-on-start \":rocket: Build started.\" \\\n  --comment-on-cancel \":crying_cat_face: Build canceled.\" \\\n  --comment-on-success \":smile_cat: Build success.\" \\\n  --comment-on-fail \":crying_cat_face: Build failed.\" \\\n  make lint test\n```\n\nCombine Pipeline \u0026 Comment\n```sh\n./with_gitlab_mr_comment --iid \"3\" \\\n  --comment-on-start \":rocket: Build started.\" \\\n  --comment-on-cancel \":crying_cat_face: Build canceled.\" \\\n  --comment-on-success \":smile_cat: Build success.\" \\\n  --comment-on-fail \":crying_cat_face: Build failed.\" \\\n  ./with_gitlab_pipeline --commit-sha \"$(git log -n 1 --pretty=format:'%H')\" \\\n    --build-system-name \"Jenkins\" --build-url \"http://localhost/jenkins/job/test/1\" \\\n    make lint test\n```\n\n\n## GitHub\n\nSet environment variables.\n```sh\nexport GITHUB_BASE_URL=https://github.com\nexport GITHUB_REPO=\"your repo\"  # e.g., iinm/bash-ci\nexport GITHUB_TOKEN=\"your token\"\n```\n\nRun command when pull request is created / updated.\n```sh\ncat \u003e ./tmp/hooks.ltsv \u003c\u003c 'HOOKS'\nhook_id:echo-example\tfilter:.labels | map(.name == \"skip-ci\") | any | not\tcmd:echo \"[$PULL_REQUEST_ID] $HEAD_REF -\u003e $BASE_REF ($PULL_REQUEST_URL)\"\nhook_id:jenkins-example\tfilter:.labels | map(.name == \"skip-ci\") | any | not\tcmd:curl --verbose --silent --show-error --fail -X POST -u $JENKINS_AUTH \"http://localhost/job/test/build\" -F json=\"$(./gitlab.bash pull_request_json_for_jenkins)\"\nHOOKS\n\n./github.bash list_pull_requests \\\n  | ./github.bash hook_pull_requests --logdir ./tmp/hook_log --hooks ./tmp/hooks.ltsv\n```\n\n- `--logdir` : stdout / stderr of cmd will be output this directory\n- `--hooks`  : hooks ltsv file\n  - `hook_id` : Unique ID (Used as a part of log file name)\n  - `filter`  : [jq](https://stedolan.github.io/jq/manual/) filter to select merge request to hook\n  - `cmd`     : Command you want to execute when merge request is created / updated; Environment variables `$PULL_REQUEST_ID`, `$HEAD_REF`, `$BASE_REF`, and `$PULL_REQUEST_URL` are automatically set\n\nRun command as GitHub Checks\n```sh\n./with_github_checks --commit-sha 91052f873c570e03b88d12f87aaed3a978986cdb \\\n  --context lint --build-url http://localhost make lint\n```\n\nRun command and comment result on pull request.\n```sh\n./with_github_pr_comment --id \"1\" \\\n  --comment-on-start \":rocket: Build started.\" \\\n  --comment-on-cancel \":crying_cat_face: Build canceled.\" \\\n  --comment-on-success \":smile_cat: Build success.\" \\\n  --comment-on-fail \":crying_cat_face: Build failed.\" \\\n  make lint\n```\n\n\n## Slack\n\nSet environment variables.\n```sh\nexport SLACK_API_TOKEN=\"your token\"\n```\n\nRun command and send Slack message.\n```sh\n./with_slack_message --channel \"random\" \\\n  --message-on-success \":smile_cat: Success\" \\\n  --message-on-fail \":crying_cat_face: Fail\" \\\n  make lint test\n```\n\nGet Slack user id from commit log.\n```sh\n./slack.bash email2userid \"$(git log -1 --pretty=format:'%ae')\"\n```\n\nPost text message.\n```sh\n./slack.bash post_text_message --channel \"#random\" --text \"Hello!\"\n```\n\nPost message.\n```sh\n./slack.bash post_message \u003c\u003c EOF\n{\n  \"as_user\": false,\n  \"username\": \"Bot\",\n  \"icon_url\": \"https://upload.wikimedia.org/wikipedia/commons/thumb/c/cd/GNOME_Builder_Icon_%28hicolor%29.svg/240px-GNOME_Builder_Icon_%28hicolor%29.svg.png\",\n  \"channel\": \"general\",\n  \"blocks\": [\n    {\n      \"type\": \"section\",\n      \"text\": {\n        \"type\": \"mrkdwn\",\n        \"text\": \":smile_cat: Build success!\"\n      }\n    },\n    {\n      \"type\": \"section\",\n      \"fields\": [\n        {\n          \"type\": \"mrkdwn\",\n          \"text\": \"*\u003chttps://google.com|GitLab MR\u003e*\"\n        },\n        {\n          \"type\": \"mrkdwn\",\n          \"text\": \"*\u003chttps://google.com|Jenkins\u003e*\"\n        }\n      ]\n    }\n  ]\n}\nEOF\n```\n\n\n## Test Bash-CI\n\nRequirements\n- shellcheck\n- busybox\n- ncurses\n- docker\n\n```sh\nmake lint test\n```\n\nor use Docker\n```sh\nbash ./with_dockerfile.test.bash 2\u003e test.log\n./with_dockerfile --verbose --run-opts \"--tty\" make lint test\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiinm%2Fbash-ci","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiinm%2Fbash-ci","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiinm%2Fbash-ci/lists"}