Skip to content

Commit 24bae40

Browse files
authored
Initialize Jongmassey/handle-empty-rstudio-prefs
0 parents  commit 24bae40

File tree

20 files changed

+265
-0
lines changed

20 files changed

+265
-0
lines changed

.devcontainer/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ehrql-main

.devcontainer/devcontainer.json

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/python
3+
{
4+
"name": "OpenSAFELY",
5+
"image": "ghcr.io/opensafely-core/research-template:v0",
6+
// Features to add to the dev container. More info: https://containers.dev/features.
7+
"features": {
8+
"ghcr.io/devcontainers/features/docker-in-docker:2": {
9+
"moby": true,
10+
"azureDnsAutoDetection": true,
11+
"installDockerBuildx": true,
12+
"version": "latest",
13+
"dockerDashComposeVersion": "v2"
14+
}
15+
},
16+
"postCreateCommand": "/bin/bash .devcontainer/postCreate.sh ${containerWorkspaceFolder}",
17+
"postAttachCommand": {
18+
"rstudio-start": "sudo rstudio-server start"
19+
},
20+
"forwardPorts": [
21+
8787
22+
],
23+
"portsAttributes": {
24+
"8787": {
25+
"label": "RStudio IDE"
26+
}
27+
},
28+
// Configure tool-specific properties.
29+
"customizations": {
30+
"codespaces": {
31+
"repositories": {
32+
"opensafely/server-instructions": {
33+
"permissions": {
34+
"contents": "read"
35+
}
36+
}
37+
}
38+
},
39+
"vscode": {
40+
"extensions": [
41+
"ms-python.python",
42+
"ms-toolsai.jupyter",
43+
"ms-toolsai.jupyter-renderers"
44+
],
45+
"settings": {
46+
"extensions.ignoreRecommendations": true,
47+
"files.autoSave": "afterDelay",
48+
"files.autoSaveDelay": 1000,
49+
"git.autofetch": true,
50+
"python.analysis.extraPaths": [".devcontainer/ehrql-main/"],
51+
"python.defaultInterpreterPath": "/opt/venv/bin/python",
52+
"python.terminal.activateEnvInCurrentTerminal": true,
53+
"python.terminal.activateEnvironment": true,
54+
"window.autoDetectColorScheme": true
55+
}
56+
}
57+
},
58+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
59+
// "remoteUser": "root"
60+
"remoteEnv": {
61+
"MAX_WORKERS": "2"
62+
}
63+
}

.devcontainer/postCreate.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
/usr/local/bin/pip3 install --user -r .devcontainer/requirements.in
6+
7+
#set R working directory
8+
! grep -q "$1" $R_HOME/etc/Rprofile.site && sudo tee -a $R_HOME/etc/Rprofile.site <<< "setwd(\"$1\")"
9+
#set RStudio working directory
10+
if [ ! -s ~/.config/rstudio/rstudio-prefs.json ]; then nullinput="-n"; fi;
11+
! grep -q "$1" ~/.config/rstudio/rstudio-prefs.json && cat ~/.config/rstudio/rstudio-prefs.json | jq "$nullinput" ". + {\"initial_working_directory\":\"$1\"}" > ~/.config/rstudio/rstudio-prefs.json
12+
13+
#download and extract latest ehrql source
14+
wget https://github.com/opensafely-core/ehrql/archive/main.zip -P .devcontainer
15+
unzip -o .devcontainer/main.zip -d .devcontainer/
16+
rm .devcontainer/main.zip

.devcontainer/requirements.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
opensafely

.gitattributes

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Set the default behavior, in case people don't have core.autocrlf set.
2+
* text=auto
3+
4+
# ensure unix line endings on windows for files that need them.
5+
*.sh eol=lf
6+
codelists/* eol=lf

.github/dependabot.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: 2
2+
3+
updates:
4+
- package-ecosystem: "github-actions"
5+
directory: "/"
6+
schedule:
7+
interval: "monthly"

.github/workflows/setup.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Setup repository
2+
on:
3+
workflow_dispatch:
4+
push:
5+
branches: [main]
6+
permissions:
7+
contents: write
8+
jobs:
9+
setup:
10+
name: Initialise OpenSAFELY project.
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Update README.md and remove action
15+
shell: bash
16+
run: |
17+
export GITHUB_REPOSITORY_OWNER="$(echo $GITHUB_REPOSITORY | awk -F/ '{print $1}')"
18+
export GITHUB_REPOSITORY_NAME="$(echo $GITHUB_REPOSITORY | awk -F/ '{print $2}')"
19+
envsubst < README.md > tmp && mv tmp README.md
20+
rm .github/workflows/setup.yaml
21+
- name: Do not run on template repository
22+
id: is_template
23+
# The only way to trigger this to run when used as a template is on
24+
# push to main. But that means it would also trigger when we push to
25+
# the template repo itself, which we do not want. So, check if we are
26+
# in a template repo
27+
run: |
28+
is_template=false
29+
curl --silent -X GET \
30+
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
31+
-H "Accept: application/vnd.github.baptiste-preview+json" \
32+
https://api.github.com/repos/$GITHUB_REPOSITORY \
33+
| jq --exit-status '.is_template == false' || is_template=true
34+
# output true/false so later actions can be skipped
35+
echo "::set-output name=is_template::$is_template"
36+
- name: Commit changes
37+
# only actually commit the changes if this is not a template repo
38+
if: steps.is_template.outputs.is_template == 'false'
39+
run: |
40+
# use the same author as the initial commit
41+
git config user.email "$(git log -1 --pretty=format:'%ae')"
42+
git config user.name "$(git log -1 --pretty=format:'%an')"
43+
git add .
44+
git commit --amend --no-edit
45+
git push origin $GITHUB_REF --force

.github/workflows/test_runner.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Test that the project is runnable
2+
3+
on: [push, workflow_dispatch]
4+
env:
5+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6+
DOCKER_RO_TOKEN: ${{ secrets.DOCKER_RO_TOKEN }}
7+
STATA_LICENSE: ${{ secrets.STATA_LICENSE }}
8+
HONEYCOMB_API_KEY: ${{ secrets.HONEYCOMB_API_KEY }}
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
name: Test the project can run, using dummy data
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
- name: Test that the project is runnable
17+
uses: opensafely-core/research-action@v2

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
*~
2+
model.log
3+
*/input.csv
4+
__pycache__
5+
.python-version
6+
/output/*
7+
metadata/*
8+
venv/
9+
.DS_Store
10+
.Rhistory
11+
.Rproj.user/

.vscode/tasks.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the tasks.json format
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"label": "OpenSAFELY run project",
8+
"type": "shell",
9+
"command": "opensafely run run_all -f",
10+
"problemMatcher": [],
11+
"group": {
12+
"kind": "build",
13+
"isDefault": true
14+
},
15+
"presentation": {
16+
"echo": true,
17+
"reveal": "always",
18+
"focus": true,
19+
"panel": "new",
20+
"showReuseMessage": false,
21+
"clear": true,
22+
}
23+
}
24+
]
25+
}

0 commit comments

Comments
 (0)