Skip to content

Commit 288ee4f

Browse files
authored
port over github actions from pxt-microbit (#386)
1 parent 41af65f commit 288ee4f

File tree

8 files changed

+334
-72
lines changed

8 files changed

+334
-72
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Check if the commit is part of a merged PR
2+
3+
on:
4+
workflow_call:
5+
outputs:
6+
is_merged_pr:
7+
description: "Whether the current push came from a merged PR"
8+
value: ${{ jobs.check-pr.outputs.is_merged_pr }}
9+
pr_head_sha:
10+
description: "The head SHA of the merged PR"
11+
value: ${{ jobs.check-pr.outputs.pr_head_sha }}
12+
13+
jobs:
14+
check-pr:
15+
runs-on: ubuntu-latest
16+
outputs:
17+
is_merged_pr: ${{ steps.parse-check-pr.outputs.is_merged_pr }}
18+
pr_head_sha: ${{ steps.parse-check-pr.outputs.pr_head_sha }}
19+
steps:
20+
- name: Check if this commit is from a merged PR
21+
id: check-pr
22+
uses: actions/github-script@v7
23+
with:
24+
result-encoding: string
25+
script: |
26+
const commitSha = context.sha;
27+
const { data: prs } = await github.rest.repos.listPullRequestsAssociatedWithCommit({
28+
owner: context.repo.owner,
29+
repo: context.repo.repo,
30+
commit_sha: commitSha
31+
});
32+
33+
if (!prs.length) {
34+
core.info('No PRs associated with this commit.');
35+
return JSON.stringify({ is_merged_pr: false, pr_head_sha: '' });
36+
}
37+
38+
const mergedPr = prs.find(pr => pr.merged_at !== null);
39+
40+
if (!mergedPr) {
41+
core.info('PRs found, but none were merged.');
42+
return JSON.stringify({ is_merged_pr: false, pr_head_sha: '' });
43+
}
44+
45+
core.info(`Found merged PR head SHA: ${mergedPr.head.sha}`);
46+
return JSON.stringify({ is_merged_pr: true, pr_head_sha: mergedPr.head.sha });
47+
48+
- name: Parse outputs
49+
id: parse-check-pr
50+
shell: bash
51+
run: |
52+
echo "Parsing result: ${{ steps.check-pr.outputs.result }}"
53+
echo "is_merged_pr=$(jq -r '.is_merged_pr' <<< '${{ steps.check-pr.outputs.result }}')" >> $GITHUB_OUTPUT
54+
echo "pr_head_sha=$(jq -r '.pr_head_sha' <<< '${{ steps.check-pr.outputs.result }}')" >> $GITHUB_OUTPUT

.github/workflows/codeql.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: "Code scanning - action"
2+
3+
on:
4+
push:
5+
branches: [ 'master', 'stable*', 'v[0-9]*' ]
6+
pull_request:
7+
# The branches below must be a subset of the branches above
8+
branches: [ master ]
9+
schedule:
10+
- cron: '0 19 * * 0'
11+
workflow_dispatch:
12+
13+
jobs:
14+
analyze:
15+
name: Analyze
16+
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
include:
21+
- language: javascript-typescript
22+
build-mode: none
23+
- language: cpp
24+
build-mode: none
25+
26+
# CodeQL runs on ubuntu-latest and windows-latest
27+
runs-on: ubuntu-latest
28+
permissions:
29+
security-events: write
30+
# required to fetch internal or private CodeQL packs
31+
packages: read
32+
33+
steps:
34+
- name: Checkout repository
35+
uses: actions/checkout@main
36+
37+
# Initializes the CodeQL tools for scanning.
38+
- name: Initialize CodeQL
39+
uses: github/codeql-action/init@v4
40+
with:
41+
languages: ${{ matrix.language }}
42+
build-mode: ${{ matrix.build-mode }}
43+
# # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
44+
# # If this step fails, then you should remove it and run the build manually (see below)
45+
# - name: Autobuild
46+
# uses: github/codeql-action/autobuild@v3
47+
48+
# ℹ️ Command-line programs to run using the OS shell.
49+
# 📚 https://git.io/JvXDl
50+
51+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
52+
# and modify them (or add more) to build your code if your project
53+
# uses a compiled language
54+
55+
#- run: |
56+
# make bootstrap
57+
# make release
58+
59+
- name: Perform CodeQL Analysis
60+
uses: github/codeql-action/analyze@v4
61+
with:
62+
category: "/language:${{matrix.language}}"

.github/workflows/is-vtag.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Whether the tag is a semver tag
2+
3+
on:
4+
workflow_call:
5+
outputs:
6+
is_vtag:
7+
description: 'Whether the tag is a semver tag'
8+
value: ${{ jobs.filter-vtags.outputs.is_vtag }}
9+
10+
jobs:
11+
filter-vtags:
12+
runs-on: ubuntu-latest
13+
outputs:
14+
is_vtag: ${{ steps.check-tag.outputs.is_vtag }}
15+
tag: ${{ steps.check-tag.outputs.tag }}
16+
steps:
17+
- name: Inputs
18+
run: |
19+
echo "GITHUB_REF_TYPE=${GITHUB_REF_TYPE}"
20+
echo "GITHUB_REF_NAME=${GITHUB_REF_NAME}"
21+
- name: Check tag pattern
22+
id: check-tag
23+
run: |
24+
if [[ "${GITHUB_REF_TYPE}" == "tag" && "${GITHUB_REF_NAME}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
25+
echo "is_vtag=true" >> "$GITHUB_OUTPUT"
26+
echo "tag=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT"
27+
else
28+
echo "is_vtag=false" >> "$GITHUB_OUTPUT"
29+
fi
30+
- name: Outputs
31+
run: echo "Step output is_vtag = ${{ steps.check-tag.outputs.is_vtag }}" && echo "Step output tag = ${{ steps.check-tag.outputs.tag }}"

.github/workflows/pxt-buildpr.yml

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: pxt-buildpush
2+
3+
on:
4+
push:
5+
branches:
6+
- '**' # Run workflow when any branch is updated
7+
tags:
8+
- '*' # Run workflow when any new tag is pushed
9+
pull_request:
10+
branches:
11+
- '**' # Run workflow for pull requests targeting any branch
12+
13+
permissions:
14+
contents: write
15+
id-token: write # Required for OIDC
16+
17+
jobs:
18+
filter-vtags:
19+
uses: ./.github/workflows/is-vtag.yml
20+
21+
tag-bump-commit:
22+
uses: ./.github/workflows/tag-bump-commit.yml
23+
needs: filter-vtags
24+
if: fromJSON(needs.filter-vtags.outputs.is_vtag || 'false') == false
25+
26+
buildpush:
27+
name: buildpush
28+
runs-on: ubuntu-latest
29+
needs: tag-bump-commit
30+
if: always() && fromJSON(needs.tag-bump-commit.outputs.did_tag || 'false') == false
31+
steps:
32+
- uses: actions/checkout@main
33+
with:
34+
fetch-depth: 0
35+
fetch-tags: true
36+
37+
- name: Use Node.js
38+
uses: actions/setup-node@main
39+
with:
40+
node-version: 20.x
41+
42+
- name: Update npm
43+
run: npm install -g npm@latest
44+
45+
- name: npm install
46+
run: |
47+
sudo apt-get install xvfb
48+
sudo npm install -g pxt
49+
npm install
50+
51+
- name: pxt ci (without publish capability)
52+
run: |
53+
pxt ci
54+
env:
55+
CHROME_BIN: chromium-browser
56+
DISPLAY: :99.0
57+
CI: true
58+
59+
buildvtag:
60+
# This job is a duplicate of pxt-buildvtag.yml's workflow
61+
name: buildvtag
62+
runs-on: ubuntu-latest
63+
needs: tag-bump-commit
64+
if: always() && fromJSON(needs.tag-bump-commit.outputs.did_tag || 'false') == true
65+
steps:
66+
- uses: actions/checkout@main
67+
with:
68+
fetch-depth: 0
69+
fetch-tags: true
70+
71+
- name: Use Node.js
72+
uses: actions/setup-node@main
73+
with:
74+
node-version: 20.x
75+
76+
- name: Update npm
77+
run: npm install -g npm@latest
78+
79+
- name: npm install
80+
run: |
81+
sudo apt-get install xvfb
82+
sudo npm install -g pxt
83+
npm install
84+
85+
- name: pxt ci (with publish capability)
86+
run: |
87+
pxt ci --publish
88+
env:
89+
CROWDIN_KEY: ${{ secrets.CROWDIN_KEY }}
90+
PXT_ACCESS_TOKEN: ${{ secrets.PXT_ACCESS_TOKEN }}
91+
PXT_RELEASE_REPO: ${{ secrets.PXT_RELEASE_REPO }}
92+
NPM_PUBLISH: true
93+
CHROME_BIN: chromium-browser
94+
DISPLAY: :99.0
95+
CI: true

.github/workflows/pxt-buildtarget.yml

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)