From d4709bed1452078419edd6d10db2bafdc905b49d Mon Sep 17 00:00:00 2001 From: Tsiry Sandratraina Date: Thu, 6 Jul 2023 19:23:09 +0000 Subject: [PATCH] Initial Commit --- .devcontainer/devcontainer.json | 26 +++++++ .github/workflows/ci.yml | 28 +++++++ .vscode/settings.json | 3 + CODE_OF_CONDUCT.md | 132 ++++++++++++++++++++++++++++++++ CONTRIBUTING.md | 53 +++++++++++++ LICENSE | 19 +++++ README.md | 128 +++++++++++++++++++++++++++++++ deno.jsonc | 0 deno.lock | 69 +++++++++++++++++ fixtures/.gitlab-ci.yml | 55 +++++++++++++ flake.lock | 61 +++++++++++++++ flake.nix | 26 +++++++ mod.ts | 3 + src/gitlab/index.ts | 4 + src/gitlab/jobs.ts | 19 +++++ src/gitlab/pipeline.ts | 42 ++++++++++ src/gitlab/pipeline_test.ts | 8 ++ 17 files changed, 676 insertions(+) create mode 100644 .devcontainer/devcontainer.json create mode 100644 .github/workflows/ci.yml create mode 100644 .vscode/settings.json create mode 100644 CODE_OF_CONDUCT.md create mode 100644 CONTRIBUTING.md create mode 100644 LICENSE create mode 100644 README.md create mode 100644 deno.jsonc create mode 100644 deno.lock create mode 100644 fixtures/.gitlab-ci.yml create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 mod.ts create mode 100644 src/gitlab/index.ts create mode 100644 src/gitlab/jobs.ts create mode 100644 src/gitlab/pipeline.ts create mode 100644 src/gitlab/pipeline_test.ts diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..c127882 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,26 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/debian +{ + "name": "Debian", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "image": "mcr.microsoft.com/devcontainers/base:bullseye", + "features": { + "ghcr.io/devcontainers/features/github-cli:1": {}, + "ghcr.io/devcontainers/features/nix:1": {} + }, + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "nix develop --experimental-features \"nix-command flakes\"" + + // Configure tool-specific properties. + // "customizations": {}, + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..3ac7dd7 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,28 @@ +name: Codecov + +# Controls when the action will run. Triggers the workflow on push or pull request +# events but only for the master branch +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: denolib/setup-deno@v2 + with: + deno-version: v1.34 + - name: Create coverage files + run: deno test --allow-read --coverage=coverage --lock-write # create coverage files + - name: Create coverage report + run: deno coverage ./coverage --lcov > coverage.lcov # create coverage report + - name: Collect coverage + uses: codecov/codecov-action@v3 # upload the report on Codecov + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + with: + file: ./coverage.lcov diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..4b9fb22 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "deno.enable": true +} \ No newline at end of file diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..da61e10 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,132 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, caste, color, religion, or sexual +identity and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the overall + community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or advances of + any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email address, + without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +[GitHub Issues](https://github.com/fluent-ci-templates/android-pipeline/issues). +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series of +actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or permanent +ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within the +community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.1, available at +[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. + +Community Impact Guidelines were inspired by +[Mozilla's code of conduct enforcement ladder][Mozilla CoC]. + +For answers to common questions about this code of conduct, see the FAQ at +[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at +[https://www.contributor-covenant.org/translations][translations]. + +[homepage]: https://www.contributor-covenant.org +[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html +[Mozilla CoC]: https://github.com/mozilla/diversity +[FAQ]: https://www.contributor-covenant.org/faq +[translations]: https://www.contributor-covenant.org/translations \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..e97da7c --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,53 @@ +# Contributing Guidelines + +Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional +documentation, we greatly value feedback and contributions from our community. + +Please read through this document before submitting any issues or pull requests to ensure we have all the necessary +information to effectively respond to your bug report or contribution. + + +## Reporting Bugs/Feature Requests + +We welcome you to use the GitHub issue tracker to report bugs or suggest features. + +When filing an issue, please check existing open, or recently closed, issues to make sure somebody else hasn't already +reported the issue. Please try to include as much information as you can. Details like these are incredibly useful: + +* A reproducible test case or series of steps +* The version of our code being used +* Any modifications you've made relevant to the bug +* Anything unusual about your environment or deployment + + +## Contributing via Pull Requests +Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that: + +1. You are working against the latest source on the *master* branch. +2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already. +3. You open an issue to discuss any significant work - we would hate for your time to be wasted. + +To send us a pull request, please: + +1. Fork the repository. +2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change. +3. Ensure local tests pass. +4. Commit to your fork using clear commit messages. +5. Send us a pull request, answering any default questions in the pull request interface. +6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation. + +GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and +[creating a pull request](https://help.github.com/articles/creating-a-pull-request/). + + +## Finding contributions to work on +Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any 'help wanted' issues is a great place to start. + + +## Code of Conduct +This project has adopted the [Contributor Covenant](https://www.contributor-covenant.org/), version 2.1, available at https://www.contributor-covenant.org/version/2/1/code_of_conduct.html. + + +## Licensing + +See the [LICENSE](LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution. \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d9ab36a --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2023 Tsiry Sandratraina + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..0134c19 --- /dev/null +++ b/README.md @@ -0,0 +1,128 @@ +# Android Pipeline + +[![deno module](https://shield.deno.dev/x/android_pipeline)](https://deno.land/x/android_pipeline) +![deno compatibility](https://shield.deno.dev/deno/^1.34) +[![](https://img.shields.io/codecov/c/gh/fluent-ci-templates/android-pipeline)](https://codecov.io/gh/fluent-ci-templates/android-pipeline) + +A ready-to-use GitLab CI Pipeline and Jobs for your Android projects. + + +## 🚀 Usage + +Quick start: + +```ts +import { GitLab } from "https://deno.land/x/android_pipeline/mod.ts"; + +const { pipeline } = GitLab; + +pipeline.write(); // Write the pipeline to the file .gitlab-ci.yml +``` + +Or, if you want to use the predefined jobs: + +```ts +import { GitlabCI } from "https://deno.land/x/fluent_gitlab_ci/mod.ts"; +import { GitLab } from "https://deno.land/x/android_pipeline/mod.ts"; + +const { assembleDebug, debugTests, lintDebug } = GitLab; + +const const pipeline = new GitlabCI() + .image("openjdk:11-jdk") + .variables({ + ANDROID_COMPILE_SDK: "30", + ANDROID_BUILD_TOOLS: "30.0.3", + ANDROID_SDK_TOOLS: "7583922", + }) + .comment("Packages installation before running script") + .beforeScript( + ` + apt-get --quiet update --yes + apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1 + export ANDROID_HOME="\${PWD}/android-home" + install -d $ANDROID_HOME + wget --output-document=$ANDROID_HOME/cmdline-tools.zip https://dl.google.com/android/repository/commandlinetools-linux-\${ANDROID_SDK_TOOLS}_latest.zip + pushd $ANDROID_HOME + unzip -d cmdline-tools cmdline-tools.zip + pushd cmdline-tools + mv cmdline-tools tools || true + popd + popd + export PATH=$PATH:\${ANDROID_HOME}/cmdline-tools/tools/bin/ + sdkmanager --version + yes | sdkmanager --licenses || true + sdkmanager "platforms;android-\${ANDROID_COMPILE_SDK}" + sdkmanager "platform-tools" + sdkmanager "build-tools;\${ANDROID_BUILD_TOOLS}" + chmod +x ./gradlew + ` + ) + .comment("Basic android and gradle stuff") + .comment("Check linting") + .addJob("lintDebug", lintDebug) + .comment("Make Project") + .addJob("assembleDebug", assembleDebug) + .comment("Run all tests, if any fails, interrupt the pipeline(fail it)") + .addJob("debugTests", debugTests); + +pipeline.write(); // Write the pipeline to the file .gitlab-ci.yml +``` + +It will generate the following `.gitlab-ci.yml` file: + +```yaml +# Do not edit this file directly. It is generated by Fluent GitLab CI + +image: openjdk:11-jdk + +variables: + ANDROID_COMPILE_SDK: "30" + ANDROID_BUILD_TOOLS: 30.0.3 + ANDROID_SDK_TOOLS: "7583922" + +# Packages installation before running script +before_script: + - apt-get --quiet update --yes + - apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1 + - export ANDROID_HOME="${PWD}/android-home" + - install -d $ANDROID_HOME + - wget --output-document=$ANDROID_HOME/cmdline-tools.zip https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_TOOLS}_latest.zip + - pushd $ANDROID_HOME + - unzip -d cmdline-tools cmdline-tools.zip + - pushd cmdline-tools + - mv cmdline-tools tools || true + - popd + - popd + - export PATH=$PATH:${ANDROID_HOME}/cmdline-tools/tools/bin/ + - sdkmanager --version + - yes | sdkmanager --licenses || true + - sdkmanager "platforms;android-${ANDROID_COMPILE_SDK}" + - sdkmanager "platform-tools" + - sdkmanager "build-tools;${ANDROID_BUILD_TOOLS}" + - chmod +x ./gradlew + +# Basic android and gradle stuff +# Check linting +lintDebug: + interruptible: true + stage: build + script: + - ./gradlew -Pci --console=plain :app:lintDebug -PbuildDir=lint + +# Make Project +assembleDebug: + interruptible: true + stage: build + script: + - ./gradlew assembleDebug + artifacts: + paths: + - app/build/outputs/ + +# Run all tests, if any fails, interrupt the pipeline(fail it) +debugTests: + interruptible: true + stage: test + script: + - ./gradlew -Pci --console=plain :app:testDebug +``` \ No newline at end of file diff --git a/deno.jsonc b/deno.jsonc new file mode 100644 index 0000000..e69de29 diff --git a/deno.lock b/deno.lock new file mode 100644 index 0000000..ede0600 --- /dev/null +++ b/deno.lock @@ -0,0 +1,69 @@ +{ + "version": "2", + "remote": { + "https://deno.land/std@0.191.0/fmt/colors.ts": "d67e3cd9f472535241a8e410d33423980bec45047e343577554d3356e1f0ef4e", + "https://deno.land/std@0.191.0/testing/_diff.ts": "1a3c044aedf77647d6cac86b798c6417603361b66b54c53331b312caeb447aea", + "https://deno.land/std@0.191.0/testing/_format.ts": "a69126e8a469009adf4cf2a50af889aca364c349797e63174884a52ff75cf4c7", + "https://deno.land/std@0.191.0/testing/asserts.ts": "e16d98b4d73ffc4ed498d717307a12500ae4f2cbe668f1a215632d19fcffc22f", + "https://deno.land/x/fluent_gitlab_ci@v0.3.2/mod.ts": "3becefe569f5c9814dffa1b534794a42b948481753a5903fa1b48d5337206ced", + "https://deno.land/x/fluent_gitlab_ci@v0.3.2/src/environment.ts": "f12ee4fb50e5100fccec29dc1d35aa430bfe8373e84286a8ab9f7b8e178f14e3", + "https://deno.land/x/fluent_gitlab_ci@v0.3.2/src/gitlabci.ts": "85d2335622c2def4a9554a9d8b8de4e62156f5d76d59a553e157bab4e6b6591f", + "https://deno.land/x/fluent_gitlab_ci@v0.3.2/src/gitlabci_spec.ts": "b60f40ecf26d243db2391aee70fdf71b133de3faaf789052020f58f98cf1b500", + "https://deno.land/x/fluent_gitlab_ci@v0.3.2/src/index.ts": "b5e374a24e3bca1d6fead0861f2c1b1e09e087a17e59297263f681ee71c972fe", + "https://deno.land/x/fluent_gitlab_ci@v0.3.2/src/job.ts": "a1ddf8d37ca33239de9d2c61f98835e585f6671748b37af8d647ebba5e1a9974", + "https://esm.sh/v126/yaml@2.3.1/denonext/yaml.mjs": "9fcc7926d1e209ab150017431a3c3fa785917d679e306c2008cf27c49a83fc54", + "https://esm.sh/v126/yaml@2.3.1/dist/compose/composer.d.ts": "400f9077cabfbf66769b5df49f9f319b64926b151a2048c0e56343b458d826a8", + "https://esm.sh/v126/yaml@2.3.1/dist/doc/Document.d.ts": "584a54f626669cf60f1bc838c6665c1bc31d6541ef3ce518d4b8114248da1629", + "https://esm.sh/v126/yaml@2.3.1/dist/doc/applyReviver.d.ts": "bc41a8e33caf4d193b0c49ec70d1e8db5ce3312eafe5447c6c1d5a2084fece12", + "https://esm.sh/v126/yaml@2.3.1/dist/doc/createNode.d.ts": "3433dceffc606d6d71af4c7abab59a2de60617590d5511debdc593a0db68e900", + "https://esm.sh/v126/yaml@2.3.1/dist/doc/directives.d.ts": "c6a1b78eb1a932d0e419b1faff8e2212df0b8baa4f13ce54981b84b383ac5233", + "https://esm.sh/v126/yaml@2.3.1/dist/errors.d.ts": "90e4e670cd0d3afd7e2751fbe8768e23f916dcbae94177484d595f8b0461573b", + "https://esm.sh/v126/yaml@2.3.1/dist/index.d.ts": "9a3697abda0f3ad142b29d9fce54bcced08ef105b57d653e1ccea5ecd82297a8", + "https://esm.sh/v126/yaml@2.3.1/dist/log.d.ts": "7c33f11a56ba4e79efc4ddae85f8a4a888e216d2bf66c863f344d403437ffc74", + "https://esm.sh/v126/yaml@2.3.1/dist/nodes/Alias.d.ts": "9ee36b1c25cfaaacce00fc756edc08a87831c876a025381d49eb970c8fa275d8", + "https://esm.sh/v126/yaml@2.3.1/dist/nodes/Collection.d.ts": "e193429103a0395cc91e2362758404917bd8a93b245f8afc59c3d671f423ff77", + "https://esm.sh/v126/yaml@2.3.1/dist/nodes/Node.d.ts": "6ddd2852d07afd0f19984761a4ee59ef63e5392f392e434e02119e44d6d8e004", + "https://esm.sh/v126/yaml@2.3.1/dist/nodes/Pair.d.ts": "779384587f797c680cc92cd70a70f8770c6c39edb313172e4cbb07ef270485c1", + "https://esm.sh/v126/yaml@2.3.1/dist/nodes/Scalar.d.ts": "70ac76145518a22bc792e3fcdd3d90b9885b36b9aa9d961acdef9021526814f6", + "https://esm.sh/v126/yaml@2.3.1/dist/nodes/YAMLMap.d.ts": "b8c933ce6942faed2100e2b744d39c881957fb609826551f4d3f837ca66aa711", + "https://esm.sh/v126/yaml@2.3.1/dist/nodes/YAMLSeq.d.ts": "ea53ae00fc7af001794e691dbbcf176928f3c454374ad21b4c6298071a69119d", + "https://esm.sh/v126/yaml@2.3.1/dist/nodes/addPairToJSMap.d.ts": "966e0d2886bd9a6444a76f9b1aef106c69001a135bcee4c3f4348b1f24edf7dd", + "https://esm.sh/v126/yaml@2.3.1/dist/nodes/identity.d.ts": "928893122ed810a8d46271b80ecc8a5598af350538379f6c68d149011af642a7", + "https://esm.sh/v126/yaml@2.3.1/dist/nodes/toJS.d.ts": "cdbef2454faa0bdc4458de435ac2a70969c4153299c94903e95ace90c2ea974e", + "https://esm.sh/v126/yaml@2.3.1/dist/options.d.ts": "3715ff389aacf7383c600297a65724c8818b895a88ceb9c89492ff9aa574f3dc", + "https://esm.sh/v126/yaml@2.3.1/dist/parse/cst-scalar.d.ts": "0ad29b6ecd25d497e4f15c3a3ad497a5c154fc300f512c24a9bd518120ca8a76", + "https://esm.sh/v126/yaml@2.3.1/dist/parse/cst-stringify.d.ts": "a7c556c5b78501cf01aaec381b8d2ff548f4c62488b545a6b600df59a97f39ce", + "https://esm.sh/v126/yaml@2.3.1/dist/parse/cst-visit.d.ts": "54195e7d453755b96b54784ac2aa6a90efe0d100cc2b185c9b0ef9f64fd64cc3", + "https://esm.sh/v126/yaml@2.3.1/dist/parse/cst.d.ts": "a50a69f2aff9d20c78f8d4287279277687ca4df845fc1462ba4f3ddf17addc6e", + "https://esm.sh/v126/yaml@2.3.1/dist/parse/lexer.d.ts": "843563f951d16e850a0be806010f630a4a71f0a55810bb9aced67c6d7774bf2f", + "https://esm.sh/v126/yaml@2.3.1/dist/parse/line-counter.d.ts": "3dfcd0a3bfa70b53135db3cf2e4ddcb7eccc3e4418ce833ae24eecd06928328f", + "https://esm.sh/v126/yaml@2.3.1/dist/parse/parser.d.ts": "cbe131ff0de13cb63a7c715c630c98d2bc4a86a9316c04674ebbef12dcffa7ba", + "https://esm.sh/v126/yaml@2.3.1/dist/public-api.d.ts": "e7891cda786cd66e81b8655da5b85894f923f7eaa0f556039f94cb5bb8126e73", + "https://esm.sh/v126/yaml@2.3.1/dist/schema/Schema.d.ts": "2e6d11d7e6c3835fb16991ba84cac3094393b77ef2ec6ebafb38e23ca3bc5f0a", + "https://esm.sh/v126/yaml@2.3.1/dist/schema/common/map.d.ts": "8edb9618c8abadf276a8f207419eeae6f11b28d5344d67697f13f24f255a74ac", + "https://esm.sh/v126/yaml@2.3.1/dist/schema/common/seq.d.ts": "0575e2d54df99037b3c582d36a3e1e4b7b52f38a5644e603c78ca4b130294f91", + "https://esm.sh/v126/yaml@2.3.1/dist/schema/common/string.d.ts": "ff1ceb61b157c7d29b81ab3e6c26f7b7b44e09cd749755073290f6d97dd50a07", + "https://esm.sh/v126/yaml@2.3.1/dist/schema/tags.d.ts": "a4f54d92fd5d11e695b116c390bec10a5dba6500532f361bcb828660f147508d", + "https://esm.sh/v126/yaml@2.3.1/dist/schema/types.d.ts": "7761d2549c775fc15ba700e158c434da650ce288e4f86c31f20f7db8b8178370", + "https://esm.sh/v126/yaml@2.3.1/dist/schema/yaml-1.1/omap.d.ts": "5bd21f1d1f25f49fdd8a05e67a62a5b24c2f867b421b26ac56d53b9dc76e0bb0", + "https://esm.sh/v126/yaml@2.3.1/dist/schema/yaml-1.1/set.d.ts": "8478bae74ede3ea89f44c18d4b0e63816f81247d8fdbaf90f13e1fe5849ae226", + "https://esm.sh/v126/yaml@2.3.1/dist/stringify/foldFlowLines.d.ts": "e27605c8932e75b14e742558a4c3101d9f4fdd32e7e9a056b2ca83f37f973945", + "https://esm.sh/v126/yaml@2.3.1/dist/stringify/stringify.d.ts": "072a3917da47d59f316b814da1eef512dea2f3222d03f2b4a13cef268ee6b782", + "https://esm.sh/v126/yaml@2.3.1/dist/stringify/stringifyNumber.d.ts": "09a3cb4eaadaa34d026c9502bf5a86e05c75bfcff57034370a5fded41d8cb51e", + "https://esm.sh/v126/yaml@2.3.1/dist/stringify/stringifyString.d.ts": "825f86b309f37643852f984ea2aa4140e2c30df46f9adff55bd17079ac3eb657", + "https://esm.sh/v126/yaml@2.3.1/dist/util.d.ts": "8357dd6eb15e8ed674954c0f57a383bfec0c352fc0467bfd06b8f8d02ee1174c", + "https://esm.sh/v126/yaml@2.3.1/dist/visit.d.ts": "59dab1f61682323c8c0a4b14ebc4627c1f507a720601717934facab661c365a4", + "https://esm.sh/yaml@v2.3.1": "b25360169240c095986f53055447582cc1b008f646c213e27db61d2a8fc2c010" + }, + "npm": { + "specifiers": { + "@types/node": "@types/node@18.11.18" + }, + "packages": { + "@types/node@18.11.18": { + "integrity": "sha512-DHQpWGjyQKSHj3ebjFI/wRKcqQcdR+MoFBygntYOZytCqNfkd2ZC4ARDJ2DQqhjH5p85Nnd3jhUJIXrszFX/JA==", + "dependencies": {} + } + } + } +} diff --git a/fixtures/.gitlab-ci.yml b/fixtures/.gitlab-ci.yml new file mode 100644 index 0000000..46b6283 --- /dev/null +++ b/fixtures/.gitlab-ci.yml @@ -0,0 +1,55 @@ +# Do not edit this file directly. It is generated by Fluent GitLab CI + +image: openjdk:11-jdk + +variables: + ANDROID_COMPILE_SDK: "30" + ANDROID_BUILD_TOOLS: 30.0.3 + ANDROID_SDK_TOOLS: "7583922" + +# Packages installation before running script +before_script: + - apt-get --quiet update --yes + - apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1 + - export ANDROID_HOME="${PWD}/android-home" + - install -d $ANDROID_HOME + - wget --output-document=$ANDROID_HOME/cmdline-tools.zip https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_TOOLS}_latest.zip + - pushd $ANDROID_HOME + - unzip -d cmdline-tools cmdline-tools.zip + - pushd cmdline-tools + - mv cmdline-tools tools || true + - popd + - popd + - export PATH=$PATH:${ANDROID_HOME}/cmdline-tools/tools/bin/ + - sdkmanager --version + - yes | sdkmanager --licenses || true + - sdkmanager "platforms;android-${ANDROID_COMPILE_SDK}" + - sdkmanager "platform-tools" + - sdkmanager "build-tools;${ANDROID_BUILD_TOOLS}" + - chmod +x ./gradlew + +# Basic android and gradle stuff +# Check linting +lintDebug: + interruptible: true + stage: build + script: + - ./gradlew -Pci --console=plain :app:lintDebug -PbuildDir=lint + +# Make Project +assembleDebug: + interruptible: true + stage: build + script: + - ./gradlew assembleDebug + artifacts: + paths: + - app/build/outputs/ + +# Run all tests, if any fails, interrupt the pipeline(fail it) +debugTests: + interruptible: true + stage: test + script: + - ./gradlew -Pci --console=plain :app:testDebug + diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..0f54683 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1687709756, + "narHash": "sha256-Y5wKlQSkgEK2weWdOu4J3riRd+kV/VCgHsqLNTTWQ/0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "dbabf0ca0c0c4bce6ea5eaf65af5cb694d2082c7", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1688652023, + "narHash": "sha256-a3mdaPxDTp5L/joHAPfduOC5i5GlpnOcWBBT7Av6nEQ=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "86f8abf1a7007b1c020c7074bd8da11383e4602a", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "release-23.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..b13ea7d --- /dev/null +++ b/flake.nix @@ -0,0 +1,26 @@ +{ + description = "A Nix-flake-based Deno development environment"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/release-23.05"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { + self, + nixpkgs, + flake-utils, + }: + flake-utils.lib.eachDefaultSystem + (system: let + pkgs = import nixpkgs { + inherit system; + }; + in { + devShells.default = pkgs.mkShell { + buildInputs = [ + pkgs.deno + ]; + }; + }); +} \ No newline at end of file diff --git a/mod.ts b/mod.ts new file mode 100644 index 0000000..5f24cff --- /dev/null +++ b/mod.ts @@ -0,0 +1,3 @@ +import * as GitLab from "./src/gitlab/index.ts"; + +export { GitLab }; diff --git a/src/gitlab/index.ts b/src/gitlab/index.ts new file mode 100644 index 0000000..6aa4cc3 --- /dev/null +++ b/src/gitlab/index.ts @@ -0,0 +1,4 @@ +import pipeline from "./pipeline.ts"; +import { lintDebug, assembleDebug, debugTests } from "./jobs.ts"; + +export { pipeline, lintDebug, assembleDebug, debugTests }; diff --git a/src/gitlab/jobs.ts b/src/gitlab/jobs.ts new file mode 100644 index 0000000..d481180 --- /dev/null +++ b/src/gitlab/jobs.ts @@ -0,0 +1,19 @@ +import { Job } from "https://deno.land/x/fluent_gitlab_ci@v0.3.2/mod.ts"; + +export const lintDebug = new Job() + .interruptible(true) + .stage("build") + .script("./gradlew -Pci --console=plain :app:lintDebug -PbuildDir=lint"); + +export const assembleDebug = new Job() + .interruptible(true) + .stage("build") + .script("./gradlew assembleDebug") + .artifacts({ + paths: ["app/build/outputs/"], + }); + +export const debugTests = new Job() + .interruptible(true) + .stage("test") + .script("./gradlew -Pci --console=plain :app:testDebug"); diff --git a/src/gitlab/pipeline.ts b/src/gitlab/pipeline.ts new file mode 100644 index 0000000..5a0f069 --- /dev/null +++ b/src/gitlab/pipeline.ts @@ -0,0 +1,42 @@ +import { GitlabCI } from "https://deno.land/x/fluent_gitlab_ci@v0.3.2/mod.ts"; +import { assembleDebug, debugTests, lintDebug } from "./jobs.ts"; + +const gitlabci = new GitlabCI() + .image("openjdk:11-jdk") + .variables({ + ANDROID_COMPILE_SDK: "30", + ANDROID_BUILD_TOOLS: "30.0.3", + ANDROID_SDK_TOOLS: "7583922", + }) + .comment("Packages installation before running script") + .beforeScript( + ` + apt-get --quiet update --yes + apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1 + export ANDROID_HOME="\${PWD}/android-home" + install -d $ANDROID_HOME + wget --output-document=$ANDROID_HOME/cmdline-tools.zip https://dl.google.com/android/repository/commandlinetools-linux-\${ANDROID_SDK_TOOLS}_latest.zip + pushd $ANDROID_HOME + unzip -d cmdline-tools cmdline-tools.zip + pushd cmdline-tools + mv cmdline-tools tools || true + popd + popd + export PATH=$PATH:\${ANDROID_HOME}/cmdline-tools/tools/bin/ + sdkmanager --version + yes | sdkmanager --licenses || true + sdkmanager "platforms;android-\${ANDROID_COMPILE_SDK}" + sdkmanager "platform-tools" + sdkmanager "build-tools;\${ANDROID_BUILD_TOOLS}" + chmod +x ./gradlew + ` + ) + .comment("Basic android and gradle stuff") + .comment("Check linting") + .addJob("lintDebug", lintDebug) + .comment("Make Project") + .addJob("assembleDebug", assembleDebug) + .comment("Run all tests, if any fails, interrupt the pipeline(fail it)") + .addJob("debugTests", debugTests); + +export default gitlabci; diff --git a/src/gitlab/pipeline_test.ts b/src/gitlab/pipeline_test.ts new file mode 100644 index 0000000..ca24710 --- /dev/null +++ b/src/gitlab/pipeline_test.ts @@ -0,0 +1,8 @@ +import pipeline from "./pipeline.ts"; +import { assertEquals } from "https://deno.land/std@0.191.0/testing/asserts.ts"; + +Deno.test(function pipelineTest() { + const expected = Deno.readTextFileSync("./fixtures/.gitlab-ci.yml"); + const actual = pipeline.toString(); + assertEquals(actual, expected); +});