From a637418e57b683449abf8894dcef2bf87c15edac Mon Sep 17 00:00:00 2001 From: Noctalin Date: Tue, 21 May 2024 11:36:25 +0200 Subject: [PATCH 01/13] Created new github action workflow for pull requests. --- .../workflows/ex3_switch_node_version.yaml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .github/workflows/ex3_switch_node_version.yaml diff --git a/.github/workflows/ex3_switch_node_version.yaml b/.github/workflows/ex3_switch_node_version.yaml new file mode 100644 index 0000000..ba2564a --- /dev/null +++ b/.github/workflows/ex3_switch_node_version.yaml @@ -0,0 +1,19 @@ +name: Switch Node version +on: + pull_request: + +jobs: + run-npm-test: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v3 + - name : setup node + uses: actions/setup-node@v3 + with: + node-version: 'lts/*' + - name: run test + shell: bash + run: | + npm install + npm test \ No newline at end of file From 5d4f594949f8f7ddae95435996e7355bfa8f61d1 Mon Sep 17 00:00:00 2001 From: Noctalin Date: Tue, 21 May 2024 11:41:49 +0200 Subject: [PATCH 02/13] Added env NODE_VERSION to define the version used and output the version on run. --- .github/workflows/ex3_switch_node_version.yaml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ex3_switch_node_version.yaml b/.github/workflows/ex3_switch_node_version.yaml index ba2564a..0225e19 100644 --- a/.github/workflows/ex3_switch_node_version.yaml +++ b/.github/workflows/ex3_switch_node_version.yaml @@ -5,15 +5,18 @@ on: jobs: run-npm-test: runs-on: ubuntu-latest + env: + NODE_VERSION: '14' steps: - name: checkout uses: actions/checkout@v3 - name : setup node uses: actions/setup-node@v3 with: - node-version: 'lts/*' + node-version: "${{ NODE_VERSION }}" - name: run test shell: bash run: | npm install - npm test \ No newline at end of file + npm test + run: node -v \ No newline at end of file From 3727492633ebe98aaabd369282ecc5981302841f Mon Sep 17 00:00:00 2001 From: Noctalin Date: Tue, 21 May 2024 11:46:10 +0200 Subject: [PATCH 03/13] Added missing env. part to access the env variable of the job. --- .github/workflows/ex3_switch_node_version.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ex3_switch_node_version.yaml b/.github/workflows/ex3_switch_node_version.yaml index 0225e19..474a19e 100644 --- a/.github/workflows/ex3_switch_node_version.yaml +++ b/.github/workflows/ex3_switch_node_version.yaml @@ -13,7 +13,7 @@ jobs: - name : setup node uses: actions/setup-node@v3 with: - node-version: "${{ NODE_VERSION }}" + node-version: "${{ env.NODE_VERSION }}" - name: run test shell: bash run: | From 15ced701e6b95ef73f842cd35869a8d434f4e97a Mon Sep 17 00:00:00 2001 From: Noctalin Date: Tue, 21 May 2024 11:47:03 +0200 Subject: [PATCH 04/13] Added showing node version as a separate step. --- .github/workflows/ex3_switch_node_version.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ex3_switch_node_version.yaml b/.github/workflows/ex3_switch_node_version.yaml index 474a19e..ced741d 100644 --- a/.github/workflows/ex3_switch_node_version.yaml +++ b/.github/workflows/ex3_switch_node_version.yaml @@ -19,4 +19,6 @@ jobs: run: | npm install npm test + - name: show node version + shell: bash run: node -v \ No newline at end of file From 1490b7c8d4ddb5bdecc00ea4645de85ad5f9ee5b Mon Sep 17 00:00:00 2001 From: Noctalin Date: Tue, 21 May 2024 12:06:25 +0200 Subject: [PATCH 05/13] Added workflow for interacting with Github API. --- .../ex3_interact_with_github_api.yaml | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/workflows/ex3_interact_with_github_api.yaml diff --git a/.github/workflows/ex3_interact_with_github_api.yaml b/.github/workflows/ex3_interact_with_github_api.yaml new file mode 100644 index 0000000..006313c --- /dev/null +++ b/.github/workflows/ex3_interact_with_github_api.yaml @@ -0,0 +1,24 @@ +name: interact with Github API +on: + pull_request: + +jobs: + create-issue: + runs-on: ubuntu-latest + steps: + - name: Install curl + shell: bash + run: | + apt update && apt install curl -y + - name: Request Github API + shell: bash + run: | + curl --request POST \ + --url https://api.github.com/repos/${{ github.repository }}/issues \ + --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \ + --header 'content-type: application/json' \ + --data '{ + "title": "Automated issue for commit: ${{ steps.short_sha.outputs.sha_short }}", + "body": "This issue was automatically created by the GitHub Action workflow **${{ github.workflow }}**. \n\n The commit hash was: _${{ steps.short_sha.outputs.sha_short }}_." + }' \ + --fail From c748061c1bcc5be593eb905b0ff46c66358313dc Mon Sep 17 00:00:00 2001 From: Noctalin Date: Tue, 21 May 2024 12:08:47 +0200 Subject: [PATCH 06/13] Use sudo for installing curl on workflow github api. --- .github/workflows/ex3_interact_with_github_api.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ex3_interact_with_github_api.yaml b/.github/workflows/ex3_interact_with_github_api.yaml index 006313c..3c3630e 100644 --- a/.github/workflows/ex3_interact_with_github_api.yaml +++ b/.github/workflows/ex3_interact_with_github_api.yaml @@ -9,7 +9,7 @@ jobs: - name: Install curl shell: bash run: | - apt update && apt install curl -y + sudo apt update && sudo apt install curl -y - name: Request Github API shell: bash run: | From c9c5195f3d4d720a33cef919665e22c7977cb4ae Mon Sep 17 00:00:00 2001 From: Noctalin Date: Tue, 21 May 2024 12:10:15 +0200 Subject: [PATCH 07/13] Output url being curled. --- .github/workflows/ex3_interact_with_github_api.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ex3_interact_with_github_api.yaml b/.github/workflows/ex3_interact_with_github_api.yaml index 3c3630e..4c1cf8e 100644 --- a/.github/workflows/ex3_interact_with_github_api.yaml +++ b/.github/workflows/ex3_interact_with_github_api.yaml @@ -13,6 +13,7 @@ jobs: - name: Request Github API shell: bash run: | + echo "https://api.github.com/repos/${{ github.repository }}/issues" curl --request POST \ --url https://api.github.com/repos/${{ github.repository }}/issues \ --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \ From c2066f08478c8cc77387e4a690a90e6af3787a61 Mon Sep 17 00:00:00 2001 From: Noctalin Date: Tue, 21 May 2024 12:13:56 +0200 Subject: [PATCH 08/13] Added missing permissions for writing to issues in workflows using github_token. --- .github/workflows/ex3_interact_with_github_api.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ex3_interact_with_github_api.yaml b/.github/workflows/ex3_interact_with_github_api.yaml index 4c1cf8e..5f00710 100644 --- a/.github/workflows/ex3_interact_with_github_api.yaml +++ b/.github/workflows/ex3_interact_with_github_api.yaml @@ -5,6 +5,8 @@ on: jobs: create-issue: runs-on: ubuntu-latest + permissions: + issues: write steps: - name: Install curl shell: bash From f9b3e6cba1a47ebad8d792cc8e382e4aa2da1308 Mon Sep 17 00:00:00 2001 From: Noctalin Date: Tue, 21 May 2024 12:22:31 +0200 Subject: [PATCH 09/13] Added step for shortening SHA. --- .github/workflows/ex3_interact_with_github_api.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/ex3_interact_with_github_api.yaml b/.github/workflows/ex3_interact_with_github_api.yaml index 5f00710..59f8a05 100644 --- a/.github/workflows/ex3_interact_with_github_api.yaml +++ b/.github/workflows/ex3_interact_with_github_api.yaml @@ -12,6 +12,11 @@ jobs: shell: bash run: | sudo apt update && sudo apt install curl -y + - name: Shorten SHA + id: short_sha + outputs: + sha_short: "${GITHUB_SHA::7}" + run: - name: Request Github API shell: bash run: | From 8fa007d4297fb5063522f358211794cbf311faa5 Mon Sep 17 00:00:00 2001 From: Noctalin Date: Tue, 21 May 2024 12:25:32 +0200 Subject: [PATCH 10/13] Fix shorten sha step. --- .github/workflows/ex3_interact_with_github_api.yaml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/ex3_interact_with_github_api.yaml b/.github/workflows/ex3_interact_with_github_api.yaml index 59f8a05..02179f6 100644 --- a/.github/workflows/ex3_interact_with_github_api.yaml +++ b/.github/workflows/ex3_interact_with_github_api.yaml @@ -14,9 +14,7 @@ jobs: sudo apt update && sudo apt install curl -y - name: Shorten SHA id: short_sha - outputs: - sha_short: "${GITHUB_SHA::7}" - run: + run: echo "sha_short=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT" - name: Request Github API shell: bash run: | From c09cf27a8ef093573cdec51296c323fe2ae1be28 Mon Sep 17 00:00:00 2001 From: Noctalin Date: Tue, 21 May 2024 14:04:38 +0200 Subject: [PATCH 11/13] Use a personal access token to call curl for creating issues. --- .github/workflows/ex3_interact_with_github_api.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ex3_interact_with_github_api.yaml b/.github/workflows/ex3_interact_with_github_api.yaml index 02179f6..e525fa4 100644 --- a/.github/workflows/ex3_interact_with_github_api.yaml +++ b/.github/workflows/ex3_interact_with_github_api.yaml @@ -21,7 +21,7 @@ jobs: echo "https://api.github.com/repos/${{ github.repository }}/issues" curl --request POST \ --url https://api.github.com/repos/${{ github.repository }}/issues \ - --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \ + --header 'authorization: Bearer ${{ secrets.PERSONAL_ACCESS_TOKEN }}' \ --header 'content-type: application/json' \ --data '{ "title": "Automated issue for commit: ${{ steps.short_sha.outputs.sha_short }}", From 112d8fcb18ddc6db708f777d8482fc38a6b70e1d Mon Sep 17 00:00:00 2001 From: Noctalin Date: Tue, 21 May 2024 14:57:30 +0200 Subject: [PATCH 12/13] Use step env for getting the github.sha instead of using replacement variable ${{ GITHUB_SHA }}. --- .github/workflows/ex3_interact_with_github_api.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ex3_interact_with_github_api.yaml b/.github/workflows/ex3_interact_with_github_api.yaml index e525fa4..65fd843 100644 --- a/.github/workflows/ex3_interact_with_github_api.yaml +++ b/.github/workflows/ex3_interact_with_github_api.yaml @@ -14,7 +14,9 @@ jobs: sudo apt update && sudo apt install curl -y - name: Shorten SHA id: short_sha - run: echo "sha_short=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT" + env: + SHA: ${{ github.sha }} + run: echo "sha_short=${SHA::7}" >> "$GITHUB_OUTPUT" - name: Request Github API shell: bash run: | From 7c79839c5349df367349760f4953528db6bed63f Mon Sep 17 00:00:00 2001 From: Noctalin Date: Tue, 21 May 2024 15:07:30 +0200 Subject: [PATCH 13/13] Using Github env instead of outputs. --- .github/workflows/ex3_interact_with_github_api.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ex3_interact_with_github_api.yaml b/.github/workflows/ex3_interact_with_github_api.yaml index 65fd843..8dc36ee 100644 --- a/.github/workflows/ex3_interact_with_github_api.yaml +++ b/.github/workflows/ex3_interact_with_github_api.yaml @@ -16,7 +16,7 @@ jobs: id: short_sha env: SHA: ${{ github.sha }} - run: echo "sha_short=${SHA::7}" >> "$GITHUB_OUTPUT" + run: echo "sha_short=${SHA::7}" >> "$GITHUB_ENV" - name: Request Github API shell: bash run: | @@ -26,7 +26,7 @@ jobs: --header 'authorization: Bearer ${{ secrets.PERSONAL_ACCESS_TOKEN }}' \ --header 'content-type: application/json' \ --data '{ - "title": "Automated issue for commit: ${{ steps.short_sha.outputs.sha_short }}", - "body": "This issue was automatically created by the GitHub Action workflow **${{ github.workflow }}**. \n\n The commit hash was: _${{ steps.short_sha.outputs.sha_short }}_." + "title": "Automated issue for commit: ${{ env.sha_short }}", + "body": "This issue was automatically created by the GitHub Action workflow **${{ github.workflow }}**. \n\n The commit hash was: _${{ env.sha_short }}_." }' \ --fail